python實(shí)現(xiàn)黑客字幕雨效果
更新時(shí)間:2018年06月21日 14:41:55 作者:xzx_kag
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)黑客字幕雨效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了python實(shí)現(xiàn)字幕雨效果的具體代碼,供大家參考,具體內(nèi)容如下
#################################### #name : HACKER EMPIRE CAPTION RAIN #import modules try : import pygame import sys from pygame.locals import * from random import randint except : print("Load modules error!!") exit() #define some datas SCREEN_WIDTH = 1366 SCREEN_HEIGHT = 768 LOW_SPEED = 30 HIGH_SPEED = 30 LOW_SIZE = 5 HIGH_SIZE = 30 FONT_SIZE = 40 FONT_NAME = "myfont.ttf" FREQUENCE = 50 times = 0 #def random color def randomcolor() : return (randint(0,255),randint(0,255),randint(0,255)) def randomspeed() : return randint(LOW_SPEED,HIGH_SPEED) def randomposition() : return (randint(0,SCREEN_WIDTH),randint(0,SCREEN_HEIGHT)) def randomsize() : return randint(LOW_SIZE,HIGH_SIZE) def randomoname() : return randint(0,100000) def randomvalue() : return randint(0,9)#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,randomcolor()) 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("HACKER EMPIRE CAPTION RAIN") clock = pygame.time.Clock() group = pygame.sprite.Group() group_count = SCREEN_WIDTH / FONT_SIZE #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_SIZE,-FONT_SIZE))) group.update() group.draw(screen) pygame.display.update() #save pictures #times += time #if times > 5000 : #pygame.image.save(screen,str(randomoname())+".png") ###########################
效果圖:
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python Web框架Pylons中使用MongoDB的例子
這篇文章主要介紹了Python Web框架Pylons中使用MongoDB 的例子,大家參考使用2013-12-12Flask框架踩坑之a(chǎn)jax跨域請(qǐng)求實(shí)現(xiàn)
這篇文章主要介紹了Flask框架踩坑之a(chǎn)jax跨域請(qǐng)求實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02淺談python for循環(huán)的巧妙運(yùn)用(迭代、列表生成式)
下面小編就為大家?guī)硪黄獪\談python for循環(huán)的巧妙運(yùn)用(迭代、列表生成式)。2017-09-09python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn)
公司使用的是企業(yè)微信,因此考慮Jenkins通知企業(yè)微信機(jī)器人的實(shí)現(xiàn)方式,本文主要介紹了python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn),感興趣的可以了解一下2021-06-06Python實(shí)現(xiàn)CAN報(bào)文轉(zhuǎn)換工具教程
這篇文章主要介紹了Python實(shí)現(xiàn)CAN報(bào)文轉(zhuǎn)換工具教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-05-05