Last active
October 8, 2018 21:11
-
-
Save sandyjmacdonald/3971d222b7e74fbb5f7a to your computer and use it in GitHub Desktop.
Displays a series of trigonometric patterns on the Pimoroni Unicorn HAT
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
#!/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