-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolors_random.py
71 lines (55 loc) · 1.85 KB
/
colors_random.py
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
import pygame, random
from pygame.locals import *
import sys
import time
pygame.init()
W, H = 600, 400
screen = pygame.display.set_mode((W, H))
font = pygame.font.SysFont('comicoro', 200)
# reloj pygame
clock = pygame.time.Clock()
t0 = time.time()
class TextColors:
def __init__(self):
self.counter = 0
self.color0 = self.color1 = self.color2 = (255)
def colorize(self):
'''Return color random range'''
self.counter += 1
if self.counter >= 5:
self.counter = 0
self.color0 = random.randrange(50, 255)
self.color1 = random.randrange(50, 255)
self.color2 = random.randrange(50, 255)
return (self.color0, self.color1, self.color2)
def update(self):
'''Update color &of text every "n" frames per second(1000fps)'''
self.counter += 1
if self.counter >= 10: #every frame in 1000
self.counter = 0
self.color0 = random.randrange(100, 255)
self.color1 = random.randrange(100, 255)
self.color2 = random.randrange(100, 255)
# texto = font.render(f'Color {self.counter:.0f}', True, (self.color0, self.color1, self.color2))
texto = font.render(f'Color', True, (self.color0, self.color1, self.color2))
screen.blit(texto, [W//2-120, H//2-100])
def main():
# counter = 0
textcolor= TextColors()
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
quit()
elif event.type == KEYDOWN:
if event.key == K_ESCAPE:
quit()
screen.fill('gray10')
textcolor.update()
clock.tick(60)
pygame.display.flip()
# pygame.display.update()
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()