
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Draw a Circle Using Arcade in Python3
Arcade is a Python library that is used to create 2D games and applications. It is an easy-to-use library that provides various functionality to create an interface for drawing shapes and images on the screen. In this article, we will use Arcade and draw a Circle in Python3.
Installing Arcade
Before we can start drawing circles, we need to install the Arcade library. You can install it using pip, the package manager for Python ?
Pip install arcade
Drawing a circle in Arcade
Method 1: Using the arcade.draw_circle() method
We can use the draw_circle method of the Arcade module to draw the circle on the screen. The steps to draw the circle in explained in the algorithm below.
Syntax
arcade.draw_circle_filled(x, y, radius, color)
The parameters passed to the arcade.draw_circle functions are ?
x ? The x-coordinate of the center point of the circle.
y ? The y-coordinate of the center point of the circle.
radius ? The radius of the circle.
color ? The color of the circle, specified as an arcade.color constant, a tuple of RGB values, or a tuple of RGBA values. For example, you could use arcade.color.RED to specify a red circle, or (255, 0, 0) to specify the same color using RGB values.
Algorithm
Import the arcade library.
Set the window width and height.
Create a window using the open_window function, passing in the width, height, and title of the window.
Give the background color of the window using the set_background_color function. In this case, we set it to white.
start the rendering process using the start_render function.
Define the center point, radius, and color of the circle we want to draw.
Draw the circle using the draw_circle_filled function, passing in the center point, radius, and color.
Finish the rendering process using the finish_render function.
Start the event loop using the run function, which displays the window and waits for user input.
Example
In the below example, the arcade library is used to create a window and draw a red circle in the center of the window. First, the window is set up with a width and height of 640 and 480 pixels, respectively. The background color is set to white, and the rendering process begins. A red circle is then drawn using the arcade.draw_circle_filled() function, specifying the center coordinates, radius, and color. Finally, the rendering process is completed, and the window is displayed until the user closes it using arcade.run().
import arcade # Set up the window WIDTH = 640 HEIGHT = 480 window = arcade.open_window(WIDTH, HEIGHT, "Drawing a Circle") # Set the background color arcade.set_background_color(arcade.color.WHITE) # Start the render process arcade.start_render() # Draw a red circle in the center of the screen x = WIDTH / 2 y = HEIGHT / 2 radius = 100 color = arcade.color.RED arcade.draw_circle_filled(x, y, radius, color) # Finish the render process and display the window arcade.finish_render() arcade.run()
Output
Method 2: Using the arcade.create_ellipse_filled() method
The arcade.create_ellipse_filled() function can be used to draw a filled ellipse (which can be used to draw a circle) on the screen.
Syntax
arcade.draw_ellipse_filled(x, y, width, height, color)
The parameters passed to the arcade.draw_ellipse_filled() function are ?
x ? The x-coordinate of the center point of the ellipse.
y ? The y-coordinate of the center point of the ellipse.
width ? The width of the ellipse.
height ? The height of the ellipse.
color ? The color of the ellipse, specified as an arcade.color constant, a tuple of RGB values, or a tuple of RGBA values.
Algorithm
Import the Arcade library using the import arcade statement.
Set the width and height of the window by creating WIDTH and HEIGHT constants.
Create a new window using the arcade.open_window() function and passing in the WIDTH, HEIGHT, and window title as arguments.
Set the background color of the window using the arcade.set_background_color() function and passing in an Arcade color constant.
Begin the rendering process using the arcade.start_render() function.
Define the center point of the ellipse by calculating the x-coordinate as WIDTH / 2 and the y-coordinate as HEIGHT / 2.
Define the width and height of the ellipse as width = 100 and height = 100.
Define the color of the ellipse as arcade.color.BLUE.
Draw the filled ellipse using the arcade.draw_ellipse_filled() function and passing in the center point, width, height, and color as arguments.
End the rendering process using the arcade.finish_render() function.
Start the event loop using the arcade.run() function, which will keep the window open until the user closes it.
Example
In the below example, the arcade library is used to create a window and draw a blue ellipse in the center of the window. First, the window is set up with a width and height of 640 and 480 pixels, respectively. The background color is set to white, and the rendering process begins. A blue ellipse is then drawn using the arcade.draw_ellipse_filled() function, specifying the center coordinates, width, height, and color. Finally, the rendering process is completed, and the window is displayed until the user closes it using arcade.run().
import arcade # Set up the window WIDTH = 640 HEIGHT = 480 window = arcade.open_window(WIDTH, HEIGHT, "Drawing a Circle") # Set the background color arcade.set_background_color(arcade.color.WHITE) # Start the render process arcade.start_render() # Draw a red circle using the create_ellipse_filled function x = WIDTH / 2 y = HEIGHT / 2 width = 100 height = 100 color = arcade.color.BLUE arcade.draw_ellipse_filled(x, y, width, height, color) # Finish the render process and display the window arcade.finish_render() arcade.run()
Output
Conclusion
In this article, we discussed how we can create a circle using the arcade library in Python. We need to create a window and the background color and use the draw_circle_filled function to draw the circle on the screen. Arcade helps create 2D games, circles, and other shapes in Python.