最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)字母閃爍效果的示例代碼

 更新時(shí)間:2022年08月01日 11:23:09   作者:樹獺叔叔  
本文主要介紹了python實(shí)現(xiàn)字母閃爍效果的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

效果圖

1. 介紹

屏幕上隨機(jī)閃爍的代碼塊,一定能滿足我們對(duì)于電影中黑客的一絲絲設(shè)想,這次,讓我們用簡(jiǎn)簡(jiǎn)單單的30行python代碼,實(shí)現(xiàn)這個(gè)效果。

前面我們借助 python 實(shí)現(xiàn)了代碼雨的效果,這一次,我們同樣借助pygamerandom兩個(gè)包,實(shí)現(xiàn)代碼閃爍的效果。

此次我們只是用pygamerandom兩個(gè)包,首先,將他們導(dǎo)入:

import pygame
import random

之后,我們進(jìn)行pygame界面的初始化工作:

# 參數(shù)
SCREENSIZE=(600,600)
BLACK=(0,0,0,13)
# 初始化
pygame.init()
font = pygame.font.SysFont('宋體', 20)
screen = pygame.display.set_mode(SCREENSIZE)
surface = pygame.Surface(SCREENSIZE, flags=pygame.SRCALPHA)
pygame.Surface.convert(surface)
surface.fill(BLACK)
screen.fill(BLACK)

之后設(shè)置一下我們字體的相關(guān)內(nèi)容:

# 內(nèi)容
lib=[chr(i) for i in range(48,48+10)] + [chr(i) for i in range(97,97+26)]   # [0-9 a-z]
texts = [font.render(l, True, (0, 255, 0)) for l in lib]
cols = list(range(40))  # 字體15, 窗口600

最后在一個(gè)循環(huán)中,更新界面并實(shí)現(xiàn)閃爍的代碼打印效果:

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    pygame.time.delay(33)
    screen.blit(surface, (0, 0))
    for i in range(n:=len(cols)):
        text = random.choice(texts)
    # 代碼閃爍
    x,y=random.randint(0,n-1),random.randint(0,n-1)
    screen.blit(text,(x*15,cols[y]*15))
    pygame.display.flip()

2. 完整代碼

完整代碼如下:

import pygame
import random
# 參數(shù)
SCREENSIZE=(600,600)
BLACK=(0,0,0,13)
# 初始化
pygame.init()
font = pygame.font.SysFont('宋體', 20)
screen = pygame.display.set_mode(SCREENSIZE)
surface = pygame.Surface(SCREENSIZE, flags=pygame.SRCALPHA)
pygame.Surface.convert(surface)
surface.fill(BLACK)
screen.fill(BLACK)
# 內(nèi)容
lib=[chr(i) for i in range(48,48+10)] + [chr(i) for i in range(97,97+26)]   # [0-9 a-z]
texts = [font.render(l, True, (0, 255, 0)) for l in lib]
cols = list(range(40))  # 字體15, 窗口600
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    pygame.time.delay(33)
    screen.blit(surface, (0, 0))
    for i in range(n:=len(cols)):
        text = random.choice(texts)
        # 隨機(jī)閃爍
        x,y=random.randint(0,n-1),random.randint(0,n-1)
        screen.blit(text,(x*15,cols[y]*15))
    pygame.display.flip()

到此這篇關(guān)于python實(shí)現(xiàn)字母閃爍效果的示例代碼的文章就介紹到這了,更多相關(guān)python 字母閃爍內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

同江市| 巧家县| 苍溪县| 高邮市| 军事| 承德市| 丰顺县| 台北县| 临江市| 阜康市| 台南县| 比如县| 资中县| 关岭| 边坝县| 乌拉特前旗| 扶绥县| 治县。| 交城县| 大埔县| 河西区| 岱山县| 成安县| 清远市| 吐鲁番市| 大庆市| 芦溪县| 正镶白旗| 澄城县| 福海县| 灵台县| 柳河县| 龙泉市| 孟村| 凉城县| 正定县| 岫岩| 梓潼县| 定南县| 长葛市| 长宁区|