-
Notifications
You must be signed in to change notification settings - Fork 0
/
Colorbase.py
60 lines (55 loc) · 1.89 KB
/
Colorbase.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
#!/usr/bin/env python3
# Written by telekrex
# under GPL-3.0 license
import pygame, sys, os
os.environ['SDL_VIDEO_CENTERED'] = '1'
tps = 60 # ticks per second
pygame.init()
pygame.display.set_caption('Colorbase R2')
monitor = (pygame.display.Info().current_w, pygame.display.Info().current_h)
fullscreen = False
clock = pygame.time.Clock() # start pygame clock
void = pygame.display.set_mode((200, 200), pygame.RESIZABLE)
colors = ['white', 'blue', 'green', 'red', 'yellow', 'cyan', 'magenta', 'gray', 'black']
index = 0 # set index of color selection
def update_display():
# updates display
# to color at index
global void
global index
global colors
void.fill(colors[index])
update_display()
r = True
while r:
clock.tick(tps)
for event in pygame.event.get():
# checking for input events
if event.type == pygame.QUIT:
# on window close, exit application
r = False
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
# on SPACE, toggle fullscreen/
# resizable windows size
if fullscreen == False:
fullscreen = True
void = pygame.display.set_mode(monitor, pygame.FULLSCREEN)
else:
fullscreen = False
void = pygame.display.set_mode((200, 200), pygame.RESIZABLE)
update_display()
if event.key == pygame.K_RETURN:
# on ENTER (aka RETURN),
# change index, thus color
if index == len(colors)-1:
index = 0
else:
index += 1
update_display()
if event.key == pygame.K_ESCAPE:
# on ESCAPE, exit application
r = False
sys.exit()
pygame.display.flip()