# Python | Ellipse (different polygons) in Kiwi

Counters | File handling | Python Methods and Functions

Kivy — it is a platform independent GUI tool in Python. Since it can run on Android, IOS, Linux, Windows, etc. It is mainly used to develop Android application, but that does not mean that it cannot be used in desktop applications.

## Ellipse:

Ellipse — this is the vertex canvas instruction. This allows you to draw a regular polygon or arc based on them. In this article, we will see that different polygons have a different number of sides, as well as many vertices on a circle.
As in Kivy, we can create polygons based on an ellipse. Note that angles in Kiwi are different from angles in mathematics. In Kiwi, the 0 degree point corresponds to the 90 degree point in mathematics.

Note:
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.

A program to demonstrate how we can make different polygons in kiw with Ellipse.

main.py file:

 ` # Code for creating different polygons with Ellipse `   ` # import nodded module ` ` import ` ` kivy `   ` # this limits the kivy version ie ` ` # below this version you cannot ` ` # use an application or software Support ` ` kivy.require (` ` "1.9.1" ` `) ` ` `  ` # Your application base class inherits from the application class. ` ` # app: always refers to your application instance ` ` from ` ` kivy.app ` ` import ` ` App `   ` # GridLayout arranges children in a matrix. ` ` # It takes up available space and ` ` # divides it into columns and rows, ` ` # then adds widgets to the resulting "cells" . ` ` from ` ` kivy.uix.gridlayout ` ` import ` GridLayout   ` # create a Layout class ` ` class ` ` Ellipsekv (GridLayout): ` ` pass `   ` # create application class ` ` class ` ` EllipseApp (App): ` ` def ` ` build (` ` self ` `): ` ` return ` ` Ellipsekv () `   ` # run application ` ` if ` ` __ name__ ` ` = ` ` = ` `' __main__' ` `: ` ` EllipseApp (). run () `

Ellipse.kv file

` `

` # Ellipse.kv code file   ####### ########################################## #   # For arcs, we have to give a start # and the ending angle. We use the default number of segments, # 180 and 5 for two elliptical arcs. # Rest part of the kv file matches another, # 6 elliptical arcs, following the same pattern.   #: set angle_start_row2 240 #: set angle_end_row2 480 #: set angle_start_row3 120 #: set angle_end_row3 240   ########################### ######################     & lt; Ellipsekv & gt ;:     # onki 4 cols: 4   ############### ###################################   # Row 1   # Create canvas canvas: Color: rgb: 0 , 0 , 1 Rectangle:   pos: self . pos size: self . size   # This will create a circle # since no segment is captured in the ellipse # so it creates a circle by default RelativeLayout:   canvas : Color: rgb: 1 ,. 8 ,. 5 Ellipse: pos: 0 , 0 size: self . size   # This will create a pentagon like # segment = 5 RelativeLayout: canvas:   Ellipse :   segments: 5   pos: 0 , 0   size: self . size   # This will create a square shape like # segment = 4 RelativeLayout: canvas:   Ellipse: segments: 4 pos: 0 , 0 size: self . size   # This will create a triangle like # segment = 3 RelativeLayout: canvas: Ellipse: segments: 3 pos: 0 , 0   size: self . size   ###################### ###########################    # Line 2   RelativeLayout: canvas:   # Assign color to everyone on line 2 Color:   rgb: 1 ,. 59 ,. 86    # Create an arc as above Ellipse: angle_start: angle_start_row2 angle_end: angle_end_row2 pos: 0 , 0   size : self . size     # Create an arc as above # segment 5 RelativeLayout: canvas: Ellipse: angle_start: angle_start_row2 angle_end: angle_end_row2 segments: 5 pos: 0 , 0   size: self . size    # Create an arc as above # segment 4   RelativeLayout: canvas: Ellipse: angle_start: angle_start_row2   angle_end: angle_end_row2 segments: 4 pos: 0 , 0   size: self . size   # Create an arc as above # segment 5 RelativeLayout:   canvas: Ellipse:   angle_start: angle_start_row2   angle_end: angle_end_row2 segments: 3 pos: 0 , 0   size: self . size   ####################### ##########################   # row 3   RelativeLayout: canvas: Color: rgb:. 5 ,. 5 ,. 5   Ellipse: angle_start: angle_start_row3 angle_end: angle_end_row3 pos: 0 , 0 size: self . size   RelativeLayout: canvas:   Ellipse: angle_start: angle_start_row3 angle_end: angle_end_row3 segments: 5 pos: 0 , 0 size: self .size   RelativeLayout: canvas: Ellipse: angle_start: angle_start_row3 angle_end: angle_end_row3 segments: 4 pos: 0 , 0 size: self . size    RelativeLayout: canvas:   Ellipse: angle_start: angle_start_row3 angle_end: angle_end_row3 segments: 3 pos: 0 , 0   size: self . size `

` `

Output:

This is the result. We have 3 rows and 4 columns. Rows 2 and 3 are arcuate, while row 1 has angles by default, 0 and 360, to form a full circle. By manually resizing the window, we can get ovals and shapes based on them. For an arc, the number of segments corresponds to the number of lines that approximate the circular part.