日报

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()

posted @   秋渡晚枫  阅读(6)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示