前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >字母雨落

字母雨落

作者头像
裴来凡
发布2022-05-29 09:41:22
6570
发布2022-05-29 09:41:22
举报
文章被收录于专栏:图像处理与模式识别研究所
代码语言:javascript
复制
import random, pygame
PANEL_width=400
PANEL_highly=500
FONT_PX=15
pygame.init()
winSur=pygame.display.set_mode((PANEL_width,PANEL_highly))
font=pygame.font.SysFont('123.ttf',22)
bg_suface=pygame.Surface((PANEL_width,PANEL_highly),flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0,0,0,28))
winSur.fill((0,0,0))
letter=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
texts=[font.render(str(letter[i]),True,(0,255,0)) for i in range(26)]
column=int(PANEL_width/FONT_PX)
drops=[0 for i in range(column)]
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            exit()
        elif event.type==pygame.KEYDOWN:
            chang=pygame.key.get_pressed()
            if (chang[32]):
                exit()
    #暂停给定的毫秒数
    pygame.time.delay(30)
    #重新编辑图像
    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>PANEL_highly or random.random()>0.95:
            drops[i]=0
    pygame.display.flip()

算法:字母雨落是是使用 pygame 库创建窗口,再定义字母的生成并让其不断的在窗口上面显示,模仿黑客帝国数字雨落效果。

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2021-10-21,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 图像处理与模式识别研究所 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档