forked from matesh/oes_matrix_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ben.py
60 lines (48 loc) · 1.8 KB
/
ben.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
import traceback
import random
import time
import sys
from renderer_common import Colour, Pixel, ROWS, COLUMNS, LED_COUNT, CLEAR_FRAME, dim, draw_rectangle, render_text, get_pixel_index
# Renderer selection according to argument. By default, it's the terminal renderer, other renderers will be used live.
if "pi" in sys.argv:
from RaspberryPiRenderer import initialise_renderer
elif "nightdriver" in sys.argv:
from NightDriverRenderer import initialise_renderer
else:
from TerminalRenderer import initialise_renderer
# red, green, or blue (based on https://stackoverflow.com/a/28999469/6837300)
def get_random_color():
rgbl=[0xFF,0x00,0x00]
random.shuffle(rgbl)
return tuple(rgbl)
# Brightness 1 so it doesn't burn my retina
BRIGHTNESS = 1
# Framerate in FPS
FRAMERATE = 20
FRAME_TIME = (60/FRAMERATE)/60
if __name__ == "__main__":
shutdown = False
# Renderer initialisation
renderer, render_pipe, terminate_renderer, renderer_terminated = initialise_renderer(render_delay=2)
try:
while not shutdown:
colour_rgb = get_random_color()
colour = Colour(colour_rgb[0], colour_rgb[1], colour_rgb[2])
# Render the text
render_text("Ben is cool!!", render_pipe, dim(colour, BRIGHTNESS))
time.sleep(1)
# Clearing matrix by putting the pre-defined CLEAR_FRAME into the render pipe
render_pipe.send(CLEAR_FRAME)
print("Terminating")
render_pipe.send(CLEAR_FRAME)
except KeyboardInterrupt:
pass
except Exception:
print("Exception in main loop")
traceback.print_exc()
finally:
print("Terminating renderer")
terminate_renderer.set()
while not renderer_terminated.is_set():
time.sleep(0.1)
print("All processes stopped")