📜  PYGLET——画圆

📅  最后修改于: 2022-05-13 01:54:51.871000             🧑  作者: Mango

PYGLET——画圆

在本文中,我们将看到如何在Python中的 PYGLET 模块中的窗口上绘制圆圈。 Pyglet 是一个易于使用但功能强大的库,用于开发视觉丰富的 GUI 应用程序,如游戏、多媒体等。窗口是占用操作系统资源的“重量级”对象。 Windows 可能显示为浮动区域,也可以设置为填充整个屏幕(全屏)。圆是由平面上的所有点组成的形状,这些点与给定的点(中心)相距给定的距离;等效地,它是由在平面中移动的点所描绘的曲线,因此它与给定点的距离是恒定的。圆是在 pyglet 中的形状模块的帮助下绘制的。
我们可以在下面给出的命令的帮助下创建一个窗口

# creating a window
window = pyglet.window.Window(width, height, title)

下面是实现

Python3
# importing pyglet module
import pyglet
 
# importing shapes from the pyglet
from pyglet import shapes
 
# width of window
width = 500
   
# height of window
height = 500
   
# caption i.e title of the window
title = "Geeksforgeeks"
   
# creating a window
window = pyglet.window.Window(width, height, title)
 
# creating a batch object
batch = pyglet.graphics.Batch()
 
 
# properties of circle
# co-ordinates of circle
circle_x = 250
circle_y = 250
 
# size of circle
# color = green
size_circle = 100
 
# creating a circle
circle1 = shapes.Circle(circle_x, circle_y, size_circle, color =(50, 225, 30), batch = batch)
 
# changing opacity of the circle1
# opacity is visibility (0 = invisible, 255 means visible)
circle1.opacity = 250
 
 
# creating another circle with other properties
# new position = circle1_position - 50
# new size = previous radius -20
# new color = red
circle2 = shapes.Circle(circle_x-50, circle_y-50, size_circle-20, color =(250, 25, 30), batch = batch)
 
# changing opacity of the circle2
circle2.opacity = 150
 
# window draw event
@window.event
def on_draw():
     
    # clear the window
    window.clear()
     
    # draw the batch
    batch.draw()
 
# run the pyglet application
pyglet.app.run()