Skip to content

Instantly share code, notes, and snippets.

@sandyjmacdonald
Last active October 8, 2018 21:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandyjmacdonald/3971d222b7e74fbb5f7a to your computer and use it in GitHub Desktop.
Save sandyjmacdonald/3971d222b7e74fbb5f7a to your computer and use it in GitHub Desktop.
Displays a series of trigonometric patterns on the Pimoroni Unicorn HAT
#!/usr/bin/env python
import unicornhat as unicorn
import time, colorsys
import math
unicorn.brightness(0.5)
def compute_z(x, y, t, pattern):
x = x + t
y = y + t
if pattern == 'parallel':
z = math.sin(x) + math.cos(x)
elif pattern == 'diagonal':
z = math.sin(x + y) + math.cos(x + y)
elif pattern == 'crisscross':
z = math.sin(x) + math.cos(y)
z = (z + 2) / 4
return z
patterns = ['parallel', 'diagonal', 'crisscross']
while True:
for pattern in patterns:
for t in range(100):
for y in range(8):
for x in range(8):
h = 0.1
s = 1.0
v = compute_z(x, y, t, pattern)
rgb = colorsys.hsv_to_rgb(h, s, v)
r = int(rgb[0]*255.0)
g = int(rgb[1]*255.0)
b = int(rgb[2]*255.0)
unicorn.set_pixel(x, y, r, g, b)
unicorn.show()
time.sleep(0.05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment