A, effects,
Second, the source
import random
import pygame
FONT_PX = 15
pygame.init()
winSur = pygame.display.set_mode((640.480))
font = pygame.font.SysFont("fangsong".20)
bg_suface = pygame.Surface((640.480), flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0.0.0.13))
winSur.fill((0.0.0))
# Related parameters
texts = [font.render(str(i), True, (0.255.0)) for i in range(10)]
colums = int(640 / 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 > 480 or random.random() > 0.95:
drops[i] = 0
pygame.display.flip()
Copy the code
Third, the principle of
The principle is very simple, random generation of numbers do not need to talk about it. So how did the numbers fade away? In fact, it is very simple, is constantly to draw a translucent black mask, many times after drawing, between the numbers will gradually disappear.