本文主要介紹了python+pygame實(shí)現(xiàn)代碼雨,分享給大家,具體如下:
效果:
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2020/12/29 12:34 # @Author : huni # @File : 代碼雨.py # @Software: PyCharm import random import pygame PANEL_width = 1600 PANEL_highly = 1000 FONT_PX = 15 pygame.init() # 創(chuàng)建一個(gè)可是窗口 winSur = pygame.display.set_mode((PANEL_width, PANEL_highly)) font = pygame.font.SysFont("123.ttf", 25) 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)) # 數(shù)字版 # texts = [font.render(str(i), True, (0, 255, 0)) for i in range(10)] #texts = [ #font.render(str(letter[i]), True, (0, 255, 0)) for i in range(26) #] # 字母版 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) ] texts = [font.render(str(i), True, (0, 255, 0)) for i in range(2)] # 按屏幕的寬帶計(jì)算可以在畫板上放幾列坐標(biāo)并生成一個(gè)列表 column = int(PANEL_width / FONT_PX) drops = [0 for i in range(column)] while True: # 從隊(duì)列中獲取事件 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() # 將暫停一段給定的毫秒數(shù) pygame.time.delay(40) # 重新編輯圖像第二個(gè)參數(shù)是坐上角坐標(biāo) winSur.blit(bg_suface, (0, 0)) for i in range(len(drops)): text = random.choice(texts) # 重新編輯每個(gè)坐標(biāo)點(diǎn)的圖像 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()
到此這篇關(guān)于python+pygame實(shí)現(xiàn)代碼雨(黑客帝國(guó)既視感)的文章就介紹到這了,更多相關(guān)pygame 代碼雨 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:內(nèi)江 廊坊 拉薩 興安盟 亳州 綿陽(yáng) 黔東 渭南
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《python+pygame實(shí)現(xiàn)代碼雨(黑客帝國(guó)既視感)》,本文關(guān)鍵詞 python+pygame,實(shí)現(xiàn),代碼,雨,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。