以下是部分代码预览:
"""pygame天空之城渐隐渐显虚像效果演示程序fade in fade out,本程序对一些图像进行一幅幅的淡入淡出显示。背景音乐为《天空之城》。
需要pygame模块安装,如果没有安装,请在命令提示符里输入 pip install pygame --user
程序中设计了一个Dream类,然后生成了一个“梦”,在“梦”中调用了相关函数实现梦的效果。
"""
__author__ = "李兴球"
__date__ = "2018/11/26"
__company__ = "风火轮少儿编程"
try:
import pygame
except:
print("没有安装pygame模块,请在安装Python3后,在命令提示符窗口输入: pip install pygame --user 进行安装。")
import os
import winsound
from pygame.locals import *
class Dream():
def __init__(self,size):
self.screen = pygame.display.set_mode(size)
self.clock = pygame.time.Clock()
self.end = False
self.title("pygame淡入淡出_渐隐渐显效果_作者:李兴球_风火轮少儿编程")
def title(self,title):
pygame.display.set_caption(title)
def playmusic(self,wavfile,loop = True):
def quit(self):
self.end = True
try:
pygame.quit()
except:
pass
def fadeshow(self,imagefile,speed=1,time=1):
"""淡入淡出显示图像,参数说明:
imagefile:图像文件
speed:速度,1-255的值
time:显示时间,秒为单位
"""
pass
if __name__ == "__main__":
"如果不是做为模块导入,那么就执行以下语句"
size = (480,360) # 尺寸元组
梦 = Dream(size) # 新建梦对象,就像做了一个梦
梦.playmusic("天空之城.wav") # 播放背景音乐
path = os.getcwd() + os.sep + "图片素材" # 要淡入淡出显示的图片文件夹
for image in os.listdir(path): # 遍历每一张图片
imagefile= path + os.sep + image # 组合历全路径文件名
if 梦.end: break # 按了关闭按钮,这个变量会为真,就退出for循环
梦.fadeshow(imagefile,speed=1)
梦.quit()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)


