代码语言:javascript复制
import random, pygame
FONT_PX=15
pygame.init()
winSur=pygame.display.set_mode((600,600))
font=pygame.font.SysFont('fangsong',20)
bg_suface=pygame.Surface((500,600),flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0,0,0,13))
winSur.fill((0,0,0))
#数字雨落
texts=[font.render(str(i),True,(0,255,0)) for i in range(10)]
colums=int(500/FONT_PX)
drops=[0 for i in range(colums)]
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
exit()
pygame.time.delay(33)
winSur.blit(bg_suface,(0,0))
for i in range(len(drops)):
text=random.choice(texts)
winSur.blit(text,(i*FONT_PX, drops[i]*FONT_PX))
drops[i] =1
if drops[i]*10>600 or random.random()>0.95:
drops[i]=0
pygame.display.flip()
算法:数字雨落是是使用 pygame 库创建窗口,再定义数字的生成并让其不断的在窗口上面显示,模仿黑客帝国数字雨落效果。
链接:https://wenku.baidu.com/view/dbb12fa2bd64783e09122b9b.html