程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Speechless how so simple—— Python implementation of Chinese subtitle rain + source code (source code can be donated)

編輯:Python

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 :

A whole cool house !!!


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)
]

Last

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 !!!

I'm a panda , I'll see you in the next article (*◡‿◡)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved