Python pygame 图形的旋转

import math
import pygame
from pygame.locals import *            # 导入pygame定义的常量

width,height = 480,360

pygame.init()

screen = pygame.display.set_mode((width,height))

square = pygame.Surface((100,100)).convert_alpha()
square.fill((0,255,255))

centerx = width//2                      # 中心点x坐标
centery = height//2                     # 中心点y坐标
angle = 0                               # 旋转角度

running = True

while running:
    event = pygame.event.poll()         # 从事件队列中取一个事件
    if event.type == QUIT:running = False
    s = pygame.transform.rotate(square,math.radians(angle)) # 旋转square   
    s_rect = s.get_rect()               # 获取surface的矩形对象
    s_rect.centerx = centerx            # 设定图形的中心点x坐标
    s_rect.centery = centery            # 设定图形的中心点y坐标
    screen.fill((0,0,0))                # 填充screen为黑色
    screen.blit(s,s_rect)               # 把旋转后的s图形按s_rect之描述贴到screen上
    pygame.display.update()             # 更新屏幕显示 
    angle +=1
    
pygame.quit()
posted @   记录——去繁就简  阅读(414)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示