Skip to content

Commit

Permalink
Aligning examples with each other
Browse files Browse the repository at this point in the history
  • Loading branch information
sandyjmacdonald committed Feb 19, 2019
1 parent 7344ed9 commit 939afb1
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 103 deletions.
2 changes: 2 additions & 0 deletions examples/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DisplayOutput():
def __init__(self):
self.hat = unicornhathd
self.hat.rotation(90)
self.hat.brightness(0.6)

def write(self, buf):
img = Image.frombytes('RGB', (64, 64), buf)
Expand All @@ -58,3 +59,4 @@ def write(self, buf):
pause()
finally:
camera.stop_recording()
unicornhathd.off()
3 changes: 2 additions & 1 deletion examples/candle.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
""")

unicornhathd.rotation(0)
unicornhathd.rotation(270)
unicornhathd.brightness(0.6)
width, height = unicornhathd.get_shape()
# buffer to contain candle "heat" data
candle = [0] * 256
Expand Down
1 change: 1 addition & 0 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
""")

unicornhathd.rotation(0)
unicornhathd.brightness(0.6)
u_width, u_height = unicornhathd.get_shape()

# Generate a lookup table for 8bit hue to RGB conversion
Expand Down
1 change: 1 addition & 0 deletions examples/forest-fire.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
scale = 3

unicornhathd.rotation(0)
unicornhathd.brightness(0.6)
width, height = unicornhathd.get_shape()

forest_width = width * scale
Expand Down
10 changes: 7 additions & 3 deletions examples/game-of-life.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

print("""Unicorn HAT HD: Game Of Life
Runs Conway's Game Of Life on your Unicorn HAT, this starts
with a random spread of life, so results may vary!
Runs Conway's Game Of Life on your Unicorn HAT HD, this
starts with a random spread of life, so results may vary!
Press Ctrl+C to exit!
""")

try:
Expand All @@ -18,7 +20,7 @@
xrange = range

unicornhathd.rotation(0)
unicornhathd.brightness(0.5)
unicornhathd.brightness(0.6)
width, height = unicornhathd.get_shape()

size = width * height
Expand Down Expand Up @@ -79,11 +81,13 @@ def show_board(self):

life = GameOfLife()


try:
while not life.all_dead():
life.next_generation()
life.show_board()
time.sleep(0.05)

except KeyboardInterrupt:
unicornhathd.clear()
unicornhathd.off()
5 changes: 3 additions & 2 deletions examples/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

import math
import time

# import random # Required for random values
# from colorsys import hsv_to_rgb # required for trippy bar colours

import unicornhathd


print("""Unicorn HAT HD: graph.py
print("""Unicorn HAT HD: Graph
This graph demo shows how you might display a range of values on UHHD.
Press Ctrl+C to exit!
""")

unicornhathd.rotation(0)
unicornhathd.rotation(90)
unicornhathd.brightness(0.6)
u_width, u_height = unicornhathd.get_shape()

Expand Down
61 changes: 37 additions & 24 deletions examples/line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,46 @@
import time
import unicornhathd

while True:
for rotation in [0, 90, 180, 270]:
print('Showing lines at rotation: {}'.format(rotation))

unicornhathd.clear()
unicornhathd.rotation(rotation)
unicornhathd.set_pixel(0, 0, 64, 64, 64)
unicornhathd.show()
time.sleep(0.5)

for x in range(1, 16):
unicornhathd.set_pixel(x, 0, 255, 0, 0)
unicornhathd.show()
time.sleep(0.5 / 16)
print("""Unicorn HAT HD: Lines
time.sleep(0.5)
Demonstrates how to draw lines on Unicorn HAT HD.
for y in range(1, 16):
unicornhathd.set_pixel(0, y, 0, 0, 255)
unicornhathd.show()
time.sleep(0.5 / 16)
Press Ctrl+C to exit!
""")

unicornhathd.brightness(0.6)

time.sleep(0.5)
try:
while True:
for rotation in [0, 90, 180, 270]:
print('Showing lines at rotation: {}'.format(rotation))

for b in range(1, 16):
unicornhathd.set_pixel(b, b, 0, 255, 0)
unicornhathd.clear()
unicornhathd.rotation(rotation)
unicornhathd.set_pixel(0, 0, 64, 64, 64)
unicornhathd.show()
time.sleep(0.5 / 16)
time.sleep(0.5)

for x in range(1, 16):
unicornhathd.set_pixel(x, 0, 255, 0, 0)
unicornhathd.show()
time.sleep(0.5 / 16)

time.sleep(0.5)

for y in range(1, 16):
unicornhathd.set_pixel(0, y, 0, 0, 255)
unicornhathd.show()
time.sleep(0.5 / 16)

time.sleep(0.5)

for b in range(1, 16):
unicornhathd.set_pixel(b, b, 0, 255, 0)
unicornhathd.show()
time.sleep(0.5 / 16)

time.sleep(0.5)

time.sleep(0.5)
except KeyboardInterrupt:
unicornhathd.off()
24 changes: 13 additions & 11 deletions examples/matrixhd.py → examples/matrix-hd.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
#!/usr/bin/env python

#
# Ported from Pimoroni Unicorn Hat example https://github.com/pimoroni/unicorn-hat/blob/master/examples/hat/matrix.py
# to unicornhat hd by aburgess@gmail.com (https://github.com/Mutiny-Games)
#
# Ported from Pimoroni Unicorn HAT example
# https://github.com/pimoroni/unicorn-hat/blob/master/examples/hat/matrix.py
# to Unicorn HAT HD by aburgess@gmail.com (https://github.com/Mutiny-Games)

import time
from random import randint

import unicornhathd as unicorn
import unicornhathd

print("""Matrix
print("""Unicorn HAT HD: Matrix HD
Follow the white rabbit...
Press Ctrl+C to exit!
""")

unicorn.rotation(270)
unicornhathd.rotation(90)
unicornhathd(0.6)

wrd_rgb = [
[154, 173, 154], [0, 255, 0], [0, 235, 0], [0, 220, 0],
Expand All @@ -34,10 +38,10 @@
y = person[1]
for rgb in wrd_rgb:
if (y <= 15) and (y >= 0):
unicorn.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2])
unicornhathd.set_pixel(person[0], y, rgb[0], rgb[1], rgb[2])
y += 1
person[1] -= 1
unicorn.show()
unicornhathd.show()
time.sleep(0.1)
clock += 1

Expand All @@ -50,6 +54,4 @@
blue_pilled_population.pop(0)

except KeyboardInterrupt:
pass
unicorn.clear()
unicorn.show()
unicornhathd.off()
1 change: 1 addition & 0 deletions examples/rainbow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
""")

unicornhathd.rotation(0)
unicornhathd.brightness(0.6)

step = 0
try:
Expand Down
33 changes: 0 additions & 33 deletions examples/raspicam.py

This file was deleted.

6 changes: 3 additions & 3 deletions examples/show-png.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

print("""Unicorn HAT HD: Show a PNG image!
This basic example shows use of the Python Pillow library:
This basic example shows use of the Python Pillow library.
The tiny 16x16 bosses in lofi.png are from Oddball:
http://forums.tigsource.com/index.php?topic=8834.0
Expand All @@ -25,8 +25,8 @@
""")

unicornhathd.rotation(90)
unicornhathd.brightness(0.5)
unicornhathd.rotation(0)
unicornhathd.brightness(0.6)

width, height = unicornhathd.get_shape()

Expand Down
14 changes: 12 additions & 2 deletions examples/snake.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@

import unicornhathd

print("""Unicorn HAT HD: Snake
If you had a Nokia phone in the 90s you'll know this.
Press Ctrl+C to exit!
""")

unicornhathd.rotation(90)
unicornhathd.brightness(0.6)

CONTROLS = {
ord('w'): 'up',
Expand Down Expand Up @@ -216,8 +226,8 @@ def main(stdscr):
print('You scored: {}'.format(snake.score))

except KeyboardInterrupt:
pass

unicornhathd.clear()
unicornhathd.off()

if __name__ == '__main__':
curses.wrapper(main)
2 changes: 2 additions & 0 deletions examples/stars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
""")

unicornhathd.brightness(0.6)

star_count = 25
star_speed = 0.05
stars = []
Expand Down
12 changes: 11 additions & 1 deletion examples/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@

import unicornhathd

print("""Unicorn HAT HD: Test
This example test the refresh rate of Unicorn HAT HD,
by rotating a random assortment of pixels one degree
at a time.
Press Ctrl+C to exit!
""")

unicornhathd.brightness(0.6)

unicornhathd.clear()
unicornhathd.set_all(10, 0, 10)

unicornhathd._buf = unicornhathd.numpy.random.randint(low=0,high=255,size=(16,16,3))

frame = 0
Expand Down

0 comments on commit 939afb1

Please sign in to comment.