📅  最后修改于: 2023-12-03 15:18:44.998000             🧑  作者: Mango
Pygame是一个Python开源的多媒体库,主要用于游戏开发。其中,pygame.draw.circle()函数用于在屏幕上绘制圆形。在本文中,我们将介绍该函数的使用方法及其参数的含义。
pygame.draw.circle(surface, color, center, radius, width=0)
import pygame
pygame.init()
screen = pygame.display.set_mode((400, 400))
pygame.display.set_caption("Pygame Circle")
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
center_x, center_y = 200, 200
radius = 100
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill(BLACK)
# 绘制填充红色圆形
pygame.draw.circle(screen, RED, (center_x, center_y), radius)
# 绘制填充绿色圆形
pygame.draw.circle(screen, GREEN, (center_x, center_y), radius-50)
# 绘制蓝色边框线宽度为5的圆形
pygame.draw.circle(screen, BLUE, (center_x, center_y), radius-100, width=5)
pygame.display.update()
clock.tick(60)