In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to use Python to make Chinese character rain effect". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to use Python to make Chinese character rain effect" can help you solve the problem.
Go directly to the code
Import pygameimport random def main (): # initialize pygame pygame.init () # default incomplete screen fullscreen = False # window not full screen width and height WIDTH, HEIGHT = 1100, 600 init_width, init_height = WIDTH, HEIGHT # block size, width High suface_height = 18 # font size font_size = 20 # create a window screen = pygame.display.set_mode ((init_width, init_height)) # font font = pygame.font.Font ('msyh.ttf', font_size) # create an image object bg_suface = pygame.Surface ((init_width, init_height)) Flags=pygame.SRCALPHA) pygame.Surface.convert (bg_suface) bg_suface.fill (pygame.Color (0,0,0,28)) # fill the background screen.fill ((0,0,0)) # the characters letter = ['Southeast University','', 'double first Class', 'University', 'University', 'College of Mechanical Engineering' '', 'Southeast','', 'double first-rate'] texts = [font.render (str (letter [I]), True, (0pr 255 letter 0)) for i in range (len (letter))] # can also be replaced with 0 1 display # texts = [# font.render ('0wow Ling True, (0LQ 255 L0)), font.render (' 1mm Last True) #] # the number of columns generated column = int (init_width / suface_height) drops = [0 for i in range (column)] while True: # Press the key to detect for event in pygame.event.get (): if event.type = = pygame.QUIT: # exit after accepting the exit event Exit () elif event.type = = pygame.KEYDOWN: # Press F11 to switch to full screen Or window if event.key = = pygame.K_F11: print ("Button F11 detected") fullscreen = not fullscreen if fullscreen: # full screen effect Parameter reset size = init_width, init_height = pygame.display.list_modes () [0] screen = pygame.display.set_mode (size, pygame.FULLSCREEN | pygame.HWSURFACE) else: init_width, init_height = WIDTH, HEIGHT screen = pygame.display.set_mode ((WIDTH) HEIGHT)) # recreate the image object bg_suface = pygame.Surface ((init_width, init_height), flags=pygame.SRCALPHA) pygame.Surface.convert (bg_suface) bg_suface.fill (pygame.Color (0,0,0) 28) column = int (init_width / suface_height) drops = [0 for i in range (column)] elif event.key = = pygame.K_ESCAPE: # Press ESC to exit exit () # delay pygame.time.delay (30) # the image object is placed on the origin coordinates of the window screen.blit (bg_suface (0,0) for i in range (len (drops)): # Random character text = random.choice (texts) # draw the character to the rainy position of the column screen.blit (text, (I * suface_height) Drops [I] * suface_height) # Update the rain coordinates drops [I] + = 1 # exceed the interface height or random number Rain location: 0 if drops [I] * suface_height > init_height or random.random () > 0.95: drops [I] = 0 # update screen pygame.display.flip () if _ _ name__ = ='_ _ main__': main ()
Running effect:
Installation method of import pygame
The package pygame is not installed. The method of installing pygame package in python
It's simple:
Use domestic source installation, Tsinghua Source Zhongke, Ali can.
Enter the virtual environment of Anaconda3 and enter the following command. Quick installation
Pip install pygame-I https://pypi.tuna.tsinghua.edu.cn/simple
Installation effect
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simpleCollecting pygame Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4c/0d/23f786eb611652b0125fcf334a0c21324922a756e6d954c50ecddfc8d4bb/pygame-2.1.2-cp36-cp36m-win_amd64.whl (8.4 MB) | ██ | 8.4 MB 119 kB/sInstalling collected packages: pygameSuccessfully installed pygame-2.1.2
Successfully installed.
This is the end of the content about "how to use Python to make the rain effect of Chinese characters". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.