In this article we will see how we can draw circles 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). A circle is a shape consisting of all points in a plane that are a given distance from a given point, the centre; equivalently it is the curve traced out by a point that moves in a plane so that its distance from a given point is constant. Circle 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 Circle method with pyglet.shapes
Syntax : shapes.Circle(x, y, size, color)
Argument : It takes first two integer i.e circle position, third integer as size of circle and fourth is tuple i.e color of circle as argument
Return : It returns Circle object
Below is the implementation
Python3
import pyglet
from pyglet import shapes
width = 500
height = 500
title = "Geeksforgeeks"
window = pyglet.window.Window(width, height, title)
batch = pyglet.graphics.Batch()
circle_x = 250
circle_y = 250
size_circle = 100
circle1 = shapes.Circle(circle_x, circle_y, size_circle, color = ( 50 , 225 , 30 ), batch = batch)
circle1.opacity = 250
circle2 = shapes.Circle(circle_x - 50 , circle_y - 50 , size_circle - 20 , color = ( 250 , 25 , 30 ), batch = batch)
circle2.opacity = 150
@window .event
def on_draw():
window.clear()
batch.draw()
pyglet.app.run()
|
Last Updated :
14 Apr, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...