欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python实现黑客字幕雨效果

时间:2021-06-23 09:20:00|栏目:Python代码|点击:

本文实例为大家分享了python实现字幕雨效果的具体代码,供大家参考,具体内容如下

#################################### 
#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") 
 
 
###########################

效果图:

上一篇:python3实现zabbix告警推送钉钉的示例

栏    目:Python代码

下一篇:Python基于win32ui模块创建弹出式菜单示例

本文标题:python实现黑客字幕雨效果

本文地址:http://www.codeinn.net/misctech/146617.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有