gpt4 book ai didi

python实现黑客字幕雨效果

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 26 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章python实现黑客字幕雨效果由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
####################################
#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")
 
 
###########################

效果图:

python实现黑客字幕雨效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.

原文链接:https://blog.csdn.net/xzx_kag/article/details/50975139 。

最后此篇关于python实现黑客字幕雨效果的文章就讲到这里了,如果你想了解更多关于python实现黑客字幕雨效果的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com