python 作业
源代码
import pygame
WIDTH = 800
HEIGHT = 600
FPS = 30
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
class Shape:
def __init__(self, x, y, width, height):
self.rect = pygame.Rect(x, y, width, height)
self.frame = 0
def update(self):
self.frame += 1
scale = 1 + 0.1 * (self.frame % 30)
self.rect.width = int(100 * scale)
self.rect.height = int(50 / scale)
def draw(self):
pygame.draw.rect(screen, (255, 255, 255), self.rect)
shape = Shape(200, 200, 100, 50)
running = True
while running:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((0, 0, 0))
shape.update()
shape.draw()
pygame.display.flip()
pygame.quit()