Python implements Chinese subtitle rain + source code

foreword

Recently, I have browsed a lot of cases about implementing code rain with Python and Pygame, and found that many of them do not explain the entire implementation process of the code in depth, and teach you how to control from 0 to 1.

Chinese character rain.

Then in the process of introduction, I will also introduce the basic knowledge of Pygame in depth, so that you can have a macro understanding of Pygame after learning from a novice.

Ok, let's officially enter the topic below.

The code implements Chinese text rain based on pygame, and the program runs screenshots:

insert image description here
insert image description here

Part of the source code:

Python学习交流Q群:906715085###
#文字雨
import pygame
import sys
import random

pygame.init()

resolution = width,height = 800,600 #设置窗口大小和标题
windowSurface = pygame.display.set_mode(resolution) #设置分辨率并得到全局的【绘图表面】
pygame.display.set_caption("中文字符雨平台")#设置标题
bgSurface = pygame.Surface((width, height), flags=pygame.SRCALPHA)
pygame.Surface.convert(bgSurface)
bgSurface.fill(pygame.Color(0, 0, 0, 35))

# 创建时钟对象
clock = pygame.time.Clock()

if __name__ == '__main__':

 str1 = "01abcdefghijklmnopqurstuvwxyz"
 str1 = "夏日的草原,早晨空气格外清新,我缠着父亲在草原上漫步。幽幽的草香迎面拂来,红艳艳。朝阳正从地平线上冉冉升起,为辽阔的草原镀上一层金色。草叶上的露珠,像镶在翡翠上的珍珠,闪着五颜六色的光华。我看到草丛中夹着许多粉红色、白色、黄色或是蓝色的不知名的花,把草原装扮得十分美丽。"
letter = list(str1)
font = pygame.font.Font("c:\windows\Fonts\simhei.ttf", 14)
texts = [
 font.render(str(letter[i]), True, (0, 255, 0)) for i in range(26)
    ]

At last

It is very simple to make subtitle rain, and the code is put on it for everyone. Friends who like it can try it out, remember to like and favorite! ! !

insert image description here

Guess you like

Origin blog.csdn.net/xff123456_/article/details/124321713
Recommended