
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 an Ellipse Using Arcade Library in Python
Python is one of the most popular languages in the programming world. The wide range of libraries and tools which are offered by the python language makes it mostly used language. Talking about the libraries we have Arcade library, a python library which works as the multimedia library helps in creating 2D games and graphics which can be included in them. In this article, we will be using the Arcade library for drawing an ellipse in Python.
What is Arcade Library?
A multimedia library in python, it provides various functions for creating 2D games, graphical objects, using shapes such as lines, circle, rectangle, etc. This library was able to solve the purpose for which it was created that is the development of more realistic graphics.
This library offers a wide range of features since it is built on top of Pyglet, a multimedia library that provides a simple interface to the developers for creating new range of games and other applications. Since this library is a built in library, there's no need of installing it. You can just import it when you need it. After importing the library you can take access of the functions under it.
For drawing different shapes Arcade has a different function for each for example
arcade.draw_circle_filled
arcade.draw_rectangle_filled
arcade.draw_polygon_filled
arcade.draw_line()
arcade.draw_point()
arcade.draw_triangle_filled()
arcade.draw_ellipse()
For drawing an ellipse using Arcade library you can use two different methods that is either by ?arcade.draw_ellipse_filled' or by ?arcade.draw_ellipse_outline()' function. We will be learning about both the functions.
Using the arcade.draw_ellipse_filled() Method
If you want to draw a filled ellipse we need to use the draw_ellipse_filled() method.
Example
In this example, we have simply defined the width and height of screen for the size of window.
Then we open a window using the arcade.open_window() function. You can set the background of the window using ?arcade.set_background_color(arcade.color.WHITE)' function.
Finally an ellipse is drawn using ?arcade.draw_ellipse_filled(SCR_WIDTH/2, SCR_HEIGHT/2, 200, 100, arcade.color.ROYAL_BLUE)' function, where five arguments are passed which define the features of the ellipse.
import arcade # defining screen dimensions SCR_WIDTH = 640 SCR_HEIGHT = 480 # create a window arcade.open_window(SCR_WIDTH, SCR_HEIGHT, "Drawing an ellipse example") arcade.set_background_color(arcade.color.WHITE) # start rendering process arcade.start_render() # filled ellipse dimensions arcade.draw_ellipse_filled(SCR_WIDTH/2, SCR_HEIGHT/2, 200, 100, arcade.color.ROYAL_BLUE) arcade.finish_render() arcade.run()
Output
The arcade.draw_ellipse_outline() Function
This method is same as the earlier one but the only exception lies while we provide six parameters. The exception while giving the parameters comes in the border width.
Here we have given 10 as the border width of the ellipse. While working with this library make sure you are providing valid parameters for the functions, define the variables first otherwise you may encounter errors such as undefined variable error.
Also check if the version of the library is not outdated. You can update the version from the python package manger by passing the command ?pip install?upgrade arcade' in the command prompt.
The only exception which comes when the filled ellipse is compared with outlined is the border width. It is not required in the case of filled ellipse.
Example
Following is an example -
import arcade # dimensions for the screen SCR_WIDTH = 640 SCR_HEIGHT = 480 # open window for drawing the object arcade.open_window(SCR_WIDTH, SCR_HEIGHT, "Drawing an ellipse outline example") arcade.set_background_color(arcade.color.WHITE_SMOKE) # start rendering process arcade.start_render() # Draw an outlined ellipse with a red color arcade.draw_ellipse_outline(SCR_WIDTH/2, SCR_HEIGHT/2, 200, 100, arcade.color.RED, 10) arcade.finish_render() arcade.run()
Output
Conclusion
In this article, we have started from the basics of the Arcade library. We have revised the basics which includes the functions of the arcade library for drawing various shapes, features of the library. For drawing ellipse, we have used two different ways, each form is drawn for different use. Follow the steps properly and avoid the errors explained in the article.