抖动的云朵_帧图生成样本示例

"""抖动的云朵_帧图生成样本示例,本程序会新建云类,它生成后会不断地抖动。
更重要的是程序会保存游戏的每一帧放在frames文件夹里面。所以可以通过继续编写程序把这些png文件合成gif或视频。
由于要不断地写磁盘,所以程序运行速度变慢了,改进的方法是跳帧,即跳过某些帧,如让index为5的倍数时才写入。
"""

import os
import time
import pygame
from pygame.locals import *
from random import randint

本文隐藏内容 登陆 后才可以浏览
def main(): """主函数""" width,height = 960,720 screen = pygame.display.set_mode((width,height)) pygame.display.set_caption("抖动的云朵_帧图生成样本示例 www.lixingqiu.com") pygame.mixer.init() pygame.mixer.music.load("inception.wav") pygame.mixer.music.play(-1,0) image = pygame.image.load("cloud.png").convert_alpha() cloud_group = pygame.sprite.Group() for i in range(20): cloud_group.add(Cloud(image,screen)) clock = pygame.time.Clock() running = True index = 0 frame_path = "frames" if not os.path.exists(frame_path):os.mkdir(frame_path) while running: for event in pygame.event.get(): if event.type == QUIT:running = False cloud_group.update() screen.fill((96,196,239)) cloud_group.draw(screen) pygame.display.update() #pygame.image.save(screen,f"{frame_path}/{index}.png") index = index + 1 clock.tick(60) pygame.quit() if __name__ == "__main__": main()