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