pygame旋转缩放演示程序,可以把这个程序发展成一个电子相册

python旋转缩放演示可做电子相册动画

"""pygame旋转缩放演示程序,可以把这个程序发展成一个电子相册"""


import os
import pygame
from time import sleep
from pygame.locals import *


images = os.getcwd() + os.sep  + "images"
width,height = 800,600

screen = pygame.display.set_mode((width,height))
pygame.display.set_caption("pygame旋转缩放演示程序可做dn 电子相册by李兴球@2018")

images = [ images + os.sep + filename for filename in os.listdir(images)]
images = [pygame.image.load(image) for image in images]
image_amounts = len(images)

index = 0
running = True
clock = pygame.time.Clock()
while running:
    image = images[index]
    for angle in range(0,361,10):
        event = pygame.event.poll()
        if event.type == QUIT: running=False ; break
        scale = angle/360
        new_image = pygame.transform.rotozoom(image,angle,scale) # 缩放与旋转同时
        rect = new_image.get_rect()                              # 获取新的矩形对象
        rect.center = (width//2,height//2)
        # new_width,new_height = rect.width,rect.height
        # x = width//2 - new_width//2                       
        # y = height//2 - new_height//2
        screen.fill((0,0,0))
        screen.blit(new_image,rect)        
        pygame.display.update()
        clock.tick(60)
    sleep(1)

You must log in to read the rest of this article. Please log in or register as a user.