Open In App

How to make a box with the help of nested loops using Python arcade?

Last Updated : 11 Oct, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Arcade library is modern framework currently used in making 2D games. Nested loop discussed here are analogous to nested loops in any other programming language.

The following tutorial will step by step explain how to draw a box with the help of nested loops using Python’s arcade module. 

  1. Import arcade library.
  2. Here we will be using circles to form a box. Thus, declare parameters, that will be used later in the program to specify spacing and margin between two circles.
  3.  Use arcade.open_window() to specify the width, height and title of the output screen.
  4. Set the background color of the output screen.(optional)
  5. Tell arcade module that you will now be sending drawing commands.
  6. Define the functionality using nested loop i.e one loop inside the other. We have defined a for loop for each row and inside that another for loop for column.
  7. Finally, we need to inform arcade module that which object we want the box should be made up of. Here, a circle is employed but you can define any other geometrical shape of your choice.
  8. Tell arcade that you have finished drawing and ask it to stop the output at the output window until the user doesn’t press exit.

Below is the implementation.

Python3




#import module
import arcade
  
#specify parameters
col_spacing = 20
row_spacing = 20
lmargin = 110
bmargin = 110
  
# Open the window
arcade.open_window(500, 500, "BOX")
  
#set the background
arcade.set_background_color(arcade.color.BABY_PINK)
  
# Start the render process.
arcade.start_render()
  
# Loop for each row
for row in range(10):
  
    # Loop for each column
    for col in range(10):
  
        # Calculate our location
        x = col * col_spacing + lmargin
        y = row * row_spacing + bmargin
  
        # Draw the objects
        arcade.draw_circle_filled(x+1, y+2, 10, arcade.color.BLUE)
  
# Finish.
arcade.finish_render()
  
# Keep the window up.
arcade.run()


Output:


Next Article

Similar Reads

Loops in Python - For, While and Nested Loops
Python programming language provides two types of Python loopshecking time. In this article, we will look at Python loops and understand their working with the help of examp - For loop and While loop to handle looping requirements. Loops in Python provides three ways for executing the loops. While all the ways provide similar basic functionality, t
9 min read
Python Nested Loops
In Python programming language there are two types of loops which are for loop and while loop. Using these loops we can create nested loops in Python. Nested loops mean loops inside a loop. For example, while loop inside the for loop, for loop inside the for loop, etc. Python Nested Loops Syntax: Outer_loop Expression: Inner_loop Expression: Statem
7 min read
Draw a tree using arcade library in Python
Drawing a tree isn't a tough task in Python using the turtle module. But, what if you can draw it using Arcade Module as well. Arcade is an object-oriented library. It can be installed like any other Python Package using an import arcade. Approach: Import arcade.Define a function to draw trees. Here, we are drawing a pine tree made up of a rectangl
3 min read
Draw an arc using Arcade in Python
The arcade library is a high-tech Python Package with an advanced set of tools for making 2D games with gripping graphics and sound. It is Object-oriented and is specially built for Python 3.6 and above versions. Arcade has two inbuilt functions for drawing arc: 1: arcade.draw_arc_outline ( ): This function is used to draw an arc which is useful fo
2 min read
Draw a happy face using Arcade Library in Python
Arcade is a Python module used for developing 2D games. For drawing a happy face, steps are as follows: Import arcade library.import arcade Open the window.arcade.open_window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE) The function used with arcade is open_window. This command opens a window with a given size i.e width and height along with screen t
3 min read
Draw a sun using arcade library Python
You might have drawn Sun using famous Python module like turtle but here we discuss how the same approach can be achieved using arcade module. The Arcade library is a modern Python Module used widely for developing 2D video games with compelling graphics and sound. Arcade is an object-oriented library. It can be installed like any other Python Pack
2 min read
Draw an ellipse using Arcade library in Python
Prerequisite: Arcade Library The Arcade library is a modern Python Module used for developing 2D video games with enthralling graphics and sound. It is an object-oriented library. It can be installed like any other Python Package in your IDE. Arcade Module has two inbuilt functions for drawing an ellipse i.e arcade.draw_ellipse_outline() and arcade
3 min read
Creating a radar sweep animation using arcade in Python
The Radar Sweep are used for displays of single level sweeps of radar data, and their display appears in the Main Display window. With the help of arcade module of Python, it is possible to perform a radar sweep animation. Before starting, it is highly recommended to revise concepts of arcade library. To perform a radar sweep animation, follow the
3 min read
Draw a triangle using Arcade in Python
Arcade is a Python library that is used for developing 2Dimensional Games. Arcade needs support for OpenGL 3.3+. In the arcade, basic drawing does not require knowledge on how to define functions or classes or how to do loops, simply we have inbuilt functions for drawing primitives. Arcade inbuilt function for drawing triangle: 1: arcade.draw_train
2 min read
Display Snowfall using arcade library in Python
In this article, we are going to display snowfall using the arcade Python Package. The Arcade library is a modern Python Module used widely for developing 2D video games with compelling graphics and sound. It is an object-oriented library and can be installed like any other Python Package. Step-by-step Approach: First and foremost step in this seri
4 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg