pygame旋转的星星.py_跟着鼠标旋转的星星

"""pygame旋转的星星.py_跟着鼠标旋转的星星,Python旋转图像示例程序,本程序用pygame的变功能让星星旋转,
作者:李兴球@2018.通过案例,你能学到如何让图片旋转.
"""

__author__ = "李兴球"
__date__ = "2018年5月"
import pygame
from pygame.locals import *

pygame.init()
screenWidth ,screenHeight = 480,360
screen = pygame.display.set_mode((screenWidth,screenHeight))
pygame.display.set_caption("旋转的星星_pygame旋转图像实例_作者:李兴球")
star = "star1.png"

class Star():
    def __init__(self,image,position):
        self.rawimage = pygame.image.load(image)   # 原始图形
        self.image = self.rawimage                 # 旋转后的图形,初始值就是原始图啦
        self.rect = self.rawimage.get_rect()       # 获取原始图形的矩形.
        self.rect.center = position
        #self.rotate_center = position
        
    def rotate(self,degree):
        self.image = pygame.transform.rotate(self.rawimage,degree)
        self.rect = self.image.get_rect()
        self.rect.center = pygame.mouse.get_pos()
        
    def draw(self):
        screen.blit(self.image,self.rect)

星星 = Star(star,(screenWidth//2,screenHeight//2))

clock = pygame.time.Clock()
running = True
d = 0
while running:
    for event in pygame.event.get():
        if event.type == QUIT:running = False
    
    星星.rotate(d)
    d=d + 2
    d = d % 360
    
    screen.fill((0,0,0))
    星星.draw()
    pygame.display.update()
    clock.tick(60)

pygame.quit()