forked from matesh/oes_matrix_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84d52ad
commit 6b8721e
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__ | ||
.history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Challenge accepted! | ||
|
||
please run ben.py | ||
|
||
Keep your expectations low. | ||
|
||
Terminal renderer doesn't render colors (as noted in README) so I wasn't able to test random color generator. | ||
|
||
A throwback to the first BASIC code I wrote at age 8. As was typical I was disrupting the class so the teacher banished me to the computer desk in the back of the room. It had a fancy TRS-80 that she didn't know what to do with. | ||
|
||
|
||
![](https://upload.wikimedia.org/wikipedia/commons/e/e4/TRS-80_Model_I_-_Rechnermuseum_Cropped.jpg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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") |