原始图片:
动态特效:
import random
import pygame
pygame.init()
bg = pygame.image.load('input.jpg')
SIZE = (bg.get_width(), bg.get_height())
screen = pygame.display.set_mode(SIZE)
pygame.display.set_caption("故宫下雪了")
snow_list = []
for i in range(200):
x = random.randrange(0, SIZE[0])
y = random.randrange(0, SIZE[1])
sx = random.randint(-1, 1)
sy = random.randint(3, 6)
snow_list.append([x, y, sx, sy])
clock = pygame.time.Clock()
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.blit(bg, (0, 0))
for i in range(len(snow_list)):
pygame.draw.circle(screen, (255, 255, 255), snow_list[i][:2], snow_list[i][3] - 3)
snow_list[i][0] += snow_list[i][2]
snow_list[i][1] += snow_list[i][3]
if snow_list[i][1] > SIZE[1]:
snow_list[i][1] = random.randrange(-50, -10)
snow_list[i][0] = random.randrange(0, SIZE[0])
pygame.display.flip()
clock.tick(20)