前言
哈嘍,我是木子,今天給大家制作一款超級炫酷的代碼啦。
提到《黑K帝國》,字符雨可謂是讓人印象深刻。
所有文章完整的素材+源碼都在????
粉絲白嫖源碼福利,請移步至CSDN社區(qū)或文末公眾hao即可免費。
??這種科技感爆棚的特效,你是否也想來一套?
這個,可以有。
最近,小編刷到抖音關(guān)于很久之前流行的代碼雨,很是心動,這炫酷的特效讓我著實愛了一
把,這不,今天早早的開始了我的代碼之旅。就為了能重現(xiàn)這次的代碼特效。
有人問效果如此震撼,實現(xiàn)起來會不會很復雜?讓我們下面看看具體的代碼吧~
正文
本文是由多個項目寫的內(nèi)容啦:
由數(shù)字代碼雨、字母代碼雨、圖形代碼雨、再到數(shù)字、字母組合代碼雨。
一、環(huán)境準備
1)運行環(huán)境
本文用到的環(huán)境如下—— Python3、Pycharm社區(qū)版,第三方模塊:pygame。部分自帶的庫
只 要安裝完 Python就可 以直接使用了,需要安裝 的庫的話看教程下???
一般安裝:pip install +模塊名
鏡像源安裝:pip install -i https://pypi.douban.com/simple/+模塊名
(之前有說過安裝報錯的幾種方式跟解決方法,不會安裝的可以去看下,還有很多國內(nèi)鏡像源 也有文章的)
二、炫酷數(shù)字代碼雨
1)代碼展示
import random, pygame
FONT_PX = 15
pygame.init()
winSur = pygame.display.set_mode((500, 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))
# 數(shù)字
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()
2)效果展示
?
?三、炫酷字母代碼雨
1)代碼展示
import random, pygame
PANEL_width = 400
PANEL_highly = 500
FONT_PX = 15
pygame.init()
# 創(chuàng)建一個窗口
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()
# 暫停給定的毫秒數(shù)
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()
2)效果展示
?
?
四、炫酷圖形代碼雨
1)代碼展示
from tkinter import *
import random, threading, time, os
# 初始雨滴縱坐標
INIT_HEIGHT = 1
# 雨滴創(chuàng)建
def rainmake(canvas, imagefile):
rainlist = []
for i in range(5):
# 根據(jù)圖片,創(chuàng)建一排福字
rainlist.append(canvas.create_image(100 + 80 * i, INIT_HEIGHT, anchor=NE, image=imagefile))
return rainlist
# 雨滴下落
def raindown(tk, canvas, imagefile, sec):
# 線程間等待
time.sleep(sec)
rainlist = rainmake(canvas, imagefile)
# 每個福字的縱坐標值
height = [INIT_HEIGHT] * 10
while True:
# 每次移動前稍等一會
time.sleep(0.2)
# 5 個福字一起移動
for i in range(5):
# 如果福字到底了,則不繼續(xù)移動
if not height[i] == 0:
# 設(shè)置下落步調(diào)
rnd = random.randint(5, 50)
canvas.move(rainlist[i], 0, rnd)
height[i] = height[i] + rnd
tk.update()
for i,h in enumerate(height):
if h > 400:
# 當福字走到最下方,則刪除
canvas.delete(rainlist[i])
tk.update()
# 清空該福的 height
height[i] = 0
print(i,h,height)
# 全到底,則跳出循環(huán)
if height == [0] * 5:
print('break:',threading.current_thread().name)
break
def lookloop(tk, canvas, thread):
aliveflg = False
while True:
# 5s 檢測一次
time.sleep(5)
for th in thread:
if th.is_alive():
aliveflg = True
else:
aliveflg = False
if aliveflg == False:
break
canvas.create_text(100 , 200, text='雨停了...', fill='red')
canvas.pack()
time.sleep(5)
tk.destroy()
def main():
# 創(chuàng)建窗口對象
tk = Tk()
tk.title('送福雨')
canvas_style = {
'bg':'white',
'height':'500',
'width':'410',
'cursor':'circle'
}
# 創(chuàng)建畫布
canvas = Canvas(tk,canvas_style)
canvas.pack()
# 圖片素材
if not os.path.exists('pic.gif'):
raise Exception('pic.gif file does not exists.')
imagefile = PhotoImage(file = 'pic.gif')
thread = []
for i in range(100):
thread.append(threading.Thread(target=raindown, args=(tk, canvas, imagefile, i)))
for t in thread:
t.start()
# 新開一個線程監(jiān)控運行中的線程
threading.Thread(target=lookloop, args=(tk, canvas, thread)).start()
# 進入消息循環(huán)
tk.mainloop()
2)效果展示
?
?
五、炫酷數(shù)字、字母代碼雨
1)代碼展示
import random
import pygame
# 初始化參數(shù)設(shè)計
win_width = 1000
win_height = 800
font_px = 15
# 創(chuàng)建窗口及文本設(shè)計
pygame.init()
winsur = pygame.display.set_mode((win_width, win_height))
font = pygame.font.SysFont('', 23)
bg_suface = pygame.Surface((win_width, win_height), flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0, 0, 0, 28))
winsur.fill((0, 0, 0))
# 文本內(nèi)容
letter = '1234567890!@#$%^&*qwertyuiopasdfghjklzxcvbnm'
texts = [font.render(letter[i], True, (0, 255, 0)) for i in range(44)]
# 顯示設(shè)計
column = int(win_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:
change = pygame.key.get_pressed()
if change[32]:
exit()
# 延時30
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 > win_height or random.random() > 0.95:
drops[i] = 0
2)效果展示
靜態(tài)截圖——
代碼效果——
打包exe文件——
無需Python無需安裝環(huán)境,雙擊即可開始運行程序,誰都可以運行這個代碼哦~簡單省事。
快發(fā)給你們那些朋友裝一下吧?哈哈哈哈.jpg?
這里就不展示exe文件了,需要的直接找我拿就好,對了除了exe打包的文件,還有詳細的視頻
講解,需要的滴滴我哈。
六、炫酷效果展示
相信大家看過許許多多的關(guān)于計算機黑客、駭客、人工智能、AI方面的電影,每當黑客入侵某
個五角大樓,某個網(wǎng)站時,都會出現(xiàn)下面類型的畫面,然后就輕而易舉的成功入侵奪取管理員
權(quán)限了,這時候的我們,心情肯定是激動的無以復加,心里大喊著:666?。。?,如果我有這
么厲害的技術(shù)就好了!這技術(shù)沒辦法給大家操作,但是類型的炫酷特效給大家演示了一波
除了代碼雨比較基礎(chǔ)的還能實現(xiàn)包括數(shù)字掉落、字符閃爍等效果哦,上面的代碼只展示一個簡
單的特效項目啦。難的(不會)↓
?
還能實現(xiàn)↓超酷的好吧~
?
只要你技術(shù)夠強,更復雜更難的也在等你來挑戰(zhàn)的啦↓
?
?
總結(jié)
好啦!內(nèi)容到這里就寫完了哈。看完這些內(nèi)容是不是感受到了一種黑客氣息撲面而來~
有沒有心動,心動的不如行動,想學習編程的小可愛趕緊行動起來吧~先從最簡單的Python編
程語言開始吧~
??完整的免費源碼領(lǐng)取處:找我吖!文末公眾hao可自行領(lǐng)取,滴滴我也可!
??推薦往期文章——
項目1.0??超級瑪麗
程序員自制游戲:超級瑪麗100%真實版,能把你玩哭了~【附源碼】
項目1.1? ?掃雷
?Pygame實戰(zhàn):據(jù)說這是史上最難掃雷游戲,沒有之一,你們感受下......
項目1.4? 水果忍者?
【Pygame實戰(zhàn)】風靡全球的切水果游戲升級版“水果忍者”上線啦,你敢來PK嘛?
項目7.0? 賽車游戲
【Pygame實戰(zhàn)】如果你是賽車愛好者:這款新賽車游戲分分鐘讓你上癮(超跑又是誰的夢想?)
項目7.1? 虐單身狗游戲
??????Pygame實戰(zhàn):慎點|虐單身狗的最高境界是…【附源碼】
項目1.1? 《極速車神打字小游戲》
【Python小游戲】通過這款專為程序員設(shè)計的《極限車神》小游戲,你的打字速度可以贏過專業(yè)錄入員,這個秘密98%的人都不知道哦~(爆贊)
??文章匯總——
匯總合集?Python—2022 |已有文章匯總 | 持續(xù)更新,直接看這篇就夠了
(更多內(nèi)容+源碼都在?文章匯總哦?。g迎閱讀喜歡的文章??~文章來源:http://www.zghlxwxcb.cn/news/detail-437460.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-437460.html
到了這里,關(guān)于【神級Python代碼】作為技術(shù)xiao白如何制作一款超炫酷的黑客主題代碼雨?牛逼就完了。(源碼分享學習)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!