Skip to content

Commit

Permalink
ben challenge entry
Browse files Browse the repository at this point in the history
  • Loading branch information
bridge-oes committed Mar 12, 2022
1 parent 84d52ad commit 6b8721e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
.history
12 changes: 12 additions & 0 deletions INSTRUCTIONS.md
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)
60 changes: 60 additions & 0 deletions ben.py
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")

0 comments on commit 6b8721e

Please sign in to comment.