看到好多高冷的字母雨,来搞一个卡哇伊一点的字母雨,满足一下少女心。
前提需要一个pygame,直接pip一下就可以了。
pip install pygame
下面就是代码了,copy就可以用了。
import random
import pygame
width = 1024
height = 800
font_width = 15
pygame.init()
winSur = pygame.display.set_mode((width,height))
font = pygame.font.SysFont("font.ttf",25)
bg_suface = pygame.Surface((width,height),flags=pygame.SRCALPHA)
pygame.Surface.convert(bg_suface)
bg_suface.fill(pygame.Color(0,0,0,28))
winSur.fill((0,0,0))
letter = ['I','l','o','v','e','y','o','u']
texts = [font.render(str(letter[i]),
True,
(random.randint(0,225),
random.randint(0,225),
random.randint(0,225)))for i in range(8)]
column = int(width/font_width)
drops = [0 for i in range(column)]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
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_width,drops[i] * font_width))
drops[i] += 1
if drops[i] * 10 > height or random.random() > 0.95:
drops[i] = 0
pygame.display.flip()