PYGLET – Drawing Arc
In this article we will see how we can draw arc on window in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a “heavyweight” object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). An arc is a portion of the circumference of a circle. In the figure above, the arc is the blue part of the circle. Strictly speaking, an arc could be a portion of some other curved shape, such as an ellipse, but it almost always refers to a circle. Arc is drawn with the help of shapes module in pyglet.
We can create a window with the help of command given below
# creating a window window = pyglet.window.Window(width, height, title)
In order to create window we use Arc method with pyglet.shapes
Syntax : shapes.Arc(arc_x, arc_y, size_arc, segments, angle, color, batch=batch)
Argument : It takes first two integer i.e arc position, third integer as size, forth is integer i.e segments, fifth is float i.e angle, sixth is color and last is batch object
Return : It returns Arc object
Below is the implementation
Python3
# importing pyglet moduleimport pyglet# importing shapes from the pygletfrom pyglet import shapes# width of windowwidth = 500 # height of windowheight = 500 # caption i.e title of the windowtitle = "Geeksforgeeks" # creating a windowwindow = pyglet.window.Window(width, height, title)# creating a batch objectbatch = pyglet.graphics.Batch()# properties of circle# co-ordinates of circlearc_x = 250arc_y = 250# size of archsize_arc = 100# segmentssegments = 5# angleangle = 20# color = greencolor = (50, 225, 30)# creating a arcarc1 = shapes.Arc(arc_x, arc_y, size_arc, segments, angle, color, batch = batch)# changing opacity of the arc1# opacity is visibility (0 = invisible, 255 means visible)arc1.opacity = 250# creating another circle with other properties# new position = circle1_position - 50# new size = previous radius -20# new color = redcolor = (255, 30, 30)# increse segmentssegments = 10# decreasing angleangle = 7# creating another arcarc2 = shapes.Arc(arc_x-50, arc_y-50, size_arc-20, segments, angle, color, batch = batch)# changing opacity of the arce2arc2.opacity = 255# window draw event@window.eventdef on_draw(): # clear the window window.clear() # draw the batch batch.draw()# run the pyglet applicationpyglet.app.run() |
Output :

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


