十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無憂售后,網(wǎng)站問題一站解決
本教程很簡(jiǎn)單吧,除了復(fù)制代碼之外,希望你也抽點(diǎn)時(shí)間去看下“注意”,教程很簡(jiǎn)單

注意
本項(xiàng)目中,需要用到文件庫(kù)“pygame”,不會(huì)的小伙伴,可以參考我的PyCharm教程里面有詳細(xì)的講解代理/IB如何添加庫(kù);
#導(dǎo)入系統(tǒng)文件庫(kù)
import pygame
import random
from pygame.locals import *
from random import randint
#定義一些窗體參數(shù)及加載字體文件
SCREEN_WIDTH = 900 # 窗體寬度
SCREEN_HEIGHT = 600 # 窗體寬度
LOW_SPEED = 4 # 字體移動(dòng)最低速度
HIGH_SPEED = 10 # 字體移動(dòng)最快速度
FONT_COLOR = (00,150,00) # 字體顏色
FONT_SIZE = 5 # 字體尺寸
FONT_NOM = 20 # 顯示字體數(shù)量 從0開始
FONT_NAME = "calibrii.ttf" # 注意字體的文件名必須與真實(shí)文件完全相同(注意ttf的大小寫),且文件名不能是中文
FREQUENCE = 10 # 時(shí)間頻度
times = 0 # 初始化時(shí)間
def randomspeed() :
return randint(LOW_SPEED,HIGH_SPEED)
def randomposition() :
return randint(0,SCREEN_WIDTH),randint(0,SCREEN_HEIGHT)
def randomoname() :
return randint(0,100000)
def randomvalue() :
return randint(0,100) # this is your own display number range
#class of sprite
class Word(pygame.sprite.Sprite) :
def init(self,bornposition) :
pygame.sprite.Sprite.init(self)
self.value = randomvalue()
self.font = pygame.font.Font(FONT_NAME,FONT_SIZE)
self.image = self.font.render(str(self.value),True,FONT_COLOR)
self.speed = randomspeed()
self.rect = self.image.get_rect()
self.rect.topleft = bornposition
def update(self) :
self.rect = self.rect.move(0,self.speed)
if self.rect.top > SCREEN_HEIGHT :
self.kill()
#init the available modules
pygame.init()
screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
pygame.display.set_caption("ViatorSun CodeRain")
clock = pygame.time.Clock()
group = pygame.sprite.Group()
group_count = int(SCREEN_WIDTH / FONT_NOM)
#mainloop
while True :
time = clock.tick(FREQUENCE)
for event in pygame.event.get() :
if event.type == QUIT :
pygame.quit()
exit()
screen.fill((0,0,0))
for i in range(0,group_count) :
group.add(Word((i * FONT_NOM,-FONT_NOM)))
group.update()
group.draw(screen)
pygame.display.update()