Python 制作出黑客帝國電影中的特效


直接先上效果圖:

代碼需要用到pygame包

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Date  : 2019/7/23
import random
import pygame
 
PANEL_width = 1800
PANEL_highly = 1000
FONT_PX = 15
 
pygame.init()
 
# 創建一個可是窗口
winSur = pygame.display.set_mode((PANEL_width, PANEL_highly))
 
font = pygame.font.SysFont('SimHei', 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))
 
# 數字版
# texts = [font.render(str(i), True, (0, 255, 0)) for i in range(10)]
 
# 字母版
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()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM