本教程很簡單吧,除了複製代碼以外,但願你也抽點時間去看下「注意」,教程很簡單html
注意dom
本項目中,須要用到文件庫「pygame」,不會的小夥伴,能夠參考個人PyCharm教程裏面有詳細的講解Axitrader返傭/Axitrader代理申請
http://www.kaifx.cn/broker/ax...;oop
import pygame字體
import randomui
from pygame.locals import *this
from random import randint代理
SCREEN_WIDTH = 900 # 窗體寬度htm
SCREEN_HEIGHT = 600 # 窗體寬度教程
LOW_SPEED = 4 # 字體移動最低速度get
HIGH_SPEED = 10 # 字體移動最快速度
FONT_COLOR = (00,150,00) # 字體顏色
FONT_SIZE = 5 # 字體尺寸
FONT_NOM = 20 # 顯示字體數量 從0開始
FONT_NAME = "calibrii.ttf" # 注意字體的文件名必須與真實文件徹底相同(注意ttf的大小寫),且文件名不能是中文
FREQUENCE = 10 # 時間頻度
times = 0 # 初始化時間
# 定義隨機參數
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 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()
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)
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()