Hello, everyone , I'm a panda
Recently, I have browsed a lot about using Python and Pygame A case of implementing code rain , I found that many of them didn't explain the whole implementation process of the code in depth , from 0 To 1 Teach you to make Chinese character rain ( In fact, it seems that any word can ).
Then in the process of introduction , I will also introduce in depth Pygame Basic knowledge of , Let you from a little white , After learning, you can also be right Pygame There is a macro understanding .
well , Now let's enter the topic .
The code is based on pygame Realized the Chinese character rain , Screenshot of program operation :
Partial source code :
Welcome to white whoring Q Group :660193417###
# Text rain
import pygame
import sys
import random
pygame.init()
resolution = width,height = 800,600 # Set window size and title
windowSurface = pygame.display.set_mode(resolution) # Set the resolution and get the global 【 Drawing surface 】
pygame.display.set_caption(" Chinese character rain platform ")# Set title
bgSurface = pygame.Surface((width, height), flags=pygame.SRCALPHA)
pygame.Surface.convert(bgSurface)
bgSurface.fill(pygame.Color(0, 0, 0, 35))
# Create a clock object
clock = pygame.time.Clock()
if __name__ == '__main__':
str1 = "01abcdefghijklmnopqurstuvwxyz"
str1 = " Summer grassland , The air is extra fresh in the morning , I pestered my father to walk on the grassland . The faint fragrance of grass is blowing in the face , Red Yanyan . The sunrise is rising slowly from the horizon , Coat the vast grassland with gold . Dew on grass leaves , Like pearls set on emerald , Shining with colorful brilliance . I saw a lot of pink in the grass 、 white 、 Unknown yellow or blue flowers , Make the grassland very beautiful ."
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)
]
Making subtitle rain is still very simple , The code will be put on it . You can try it if you like , Remember to like the collection !!!