Python | Ellipse (different polygons) in Kivy
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows, etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
Ellipse is a vertex canvas instruction. It allows drawing of a regular polygon, or an arc based on them. In this article, we will see different polygons have different number of sides and also many vertices on circle.
As in Kivy, we can make polygons based on an ellipse. Note, the angles in Kivy, are different than those in math. In Kivy, the 0-degree point, corresponds to the 90 degree-point, in math.
These are the formulas for x and y. These math formulas assume the center is 0, 0. Thus, after calculations are done, there has to be a translation by x of a and y of b. The width is 2a, and height is 2b.
N segments = N vertices
1) angle[i]= i*360/n ; i=0 to n
2) x[i]=a cos(angle[i])
3) y[i]=b sin(angle[i])
4) In kivy 12’o clock is 0 degree and increases clockwise but in math 3’o clock is 0 degree increases counter clockwise.
Program to show how we can make different polygon in kivy by Ellipse.
This is the result. We have 3 rows and 4 columns. Rows 2 and 3 are arc shapes, while Row1 has the default angles, 0 and 360 to form a complete circle. By changing the size of the window manually, we can get ovals, and shapes based on them. For the arc, the number of segments, corresponds to the number of lines that approximate the circular portion.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course