pygame有没有办法把矩形变成圆形?
Is there a way to turn a rectangle into a circle in pygame?
这是我的自动取款机密码。它在圆的顶部输出一个正方形。我想让正方形有点“变成”圆。
import pygame
GREEN = (0,255,0)
pygame.init()
pygame.display.set_caption("Game TITLE")
screen = pygame.display.set_mode((400,400))
quitVar = True
while quitVar == True:
screen.fill(WHITE)
pygame.draw.rect(screen, GREEN, (100,100,200,200))
pygame.draw.circle(screen, GREEN, (200,200),100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitVar = False
pygame.display.update()
pygame.quit()
您可以在 Pygame 中绘制带圆角的矩形(参见 )。将角半径从 0 动画化到圆的半径:
import pygame
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
pygame.init()
pygame.display.set_caption("Game TITLE")
screen = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()
radius = 0
step = 1
quitVar = True
while quitVar == True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitVar = False
screen.fill(WHITE)
pygame.draw.rect(screen, GREEN, (100, 100, 200, 200), border_radius = radius)
pygame.display.update()
radius += step
if radius <= 0 or radius >= 100:
step *= -1
pygame.quit()
这是我的自动取款机密码。它在圆的顶部输出一个正方形。我想让正方形有点“变成”圆。
import pygame
GREEN = (0,255,0)
pygame.init()
pygame.display.set_caption("Game TITLE")
screen = pygame.display.set_mode((400,400))
quitVar = True
while quitVar == True:
screen.fill(WHITE)
pygame.draw.rect(screen, GREEN, (100,100,200,200))
pygame.draw.circle(screen, GREEN, (200,200),100)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitVar = False
pygame.display.update()
pygame.quit()
您可以在 Pygame 中绘制带圆角的矩形(参见
import pygame
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
pygame.init()
pygame.display.set_caption("Game TITLE")
screen = pygame.display.set_mode((400,400))
clock = pygame.time.Clock()
radius = 0
step = 1
quitVar = True
while quitVar == True:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quitVar = False
screen.fill(WHITE)
pygame.draw.rect(screen, GREEN, (100, 100, 200, 200), border_radius = radius)
pygame.display.update()
radius += step
if radius <= 0 or radius >= 100:
step *= -1
pygame.quit()