Skip to content

Instantly share code, notes, and snippets.

@rhooper
Created February 23, 2021 15:43
Show Gist options
  • Save rhooper/b79fda39c0648c2557329faae42c0f61 to your computer and use it in GitHub Desktop.
Save rhooper/b79fda39c0648c2557329faae42c0f61 to your computer and use it in GitHub Desktop.
ulab rainbow heart wall
try:
import board
import neopixel
pixel_pin = board.D10
except NotImplementedError:
pass
try:
import ulab as np
except ImportError:
import numpy as np
from adafruit_led_animation.color import colorwheel
x_width = 20
y_height = 13
num_pixels = x_width * y_height
heart = np.array([
57, 59, 60, 66, 45, 30, 23, 31, 43, 89, 52, 37, 32, 35, 50, 106, 108,
110, 113, 118, 58, 60, 64, 47, 209, 232, 229, 187, 164, 27, 203, 199,
16, 162, 167, 53, 109, 112, 115, 121, 61, 63, 67, 28, 219, 235, 236,
230, 19, 190, 216, 223, 20, 11, 168, 34, 111, 114, 119, 126, 62, 65,
70, 3, 220, 231, 234, 233, 228, 224, 222, 218, 13, 195, 186, 1, 114,
117, 123, 132, 66, 69, 72, 24, 12, 217, 225, 227, 226, 221, 21, 211,
200, 191, 183, 25, 116, 122, 129, 136, 68, 71, 76, 36, 163, 18, 214,
215, 22, 213, 212, 204, 194, 189, 177, 38, 120, 126, 133, 143, 71,
74, 79, 48, 165, 10, 14, 17, 15, 210, 205, 198, 5, 185, 180, 54, 124,
131, 139, 146, 73, 77, 82, 86, 29, 165, 206, 208, 207, 202, 197, 9,
188, 177, 26, 122, 130, 138, 144, 150, 75, 80, 84, 89, 55, 170, 166,
201, 196, 193, 8, 2, 174, 181, 56, 127, 136, 142, 149, 153, 78, 83,
88, 92, 95, 49, 171, 182, 192, 7, 6, 184, 179, 46, 125, 134, 140, 148,
152, 156, 81, 87, 91, 94, 97, 100, 42, 173, 169, 4, 0, 178, 40, 124,
132, 139, 145, 151, 155, 159, 85, 90, 93, 96, 99, 102, 104, 44, 175,
172, 176, 39, 121, 128, 137, 142, 150, 154, 158, 160, 88, 92, 95, 98,
101, 103, 105, 107, 51, 33, 41, 120, 126, 135, 141, 147, 153, 157, 160, 161],
dtype=np.uint8)
for line in range(13):
if line % 2 == 0:
offset = line * 20
heart[offset:offset + 20] = heart[offset:offset + 20]
try:
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
except NameError:
pixels = np.zeros(len(heart) * 3, dtype=np.uint8)
heart = np.flip(heart.reshape((y_height, x_width)), axis=0).flatten()
cw = colorwheel(0)
if isinstance(cw, tuple):
fixer = lambda x: x
else:
fixer = lambda x: (x >> 16, x >> 8 & 0xff, x & 0xff)
palette = np.array([fixer(colorwheel(x)) for x in range(256)], dtype=np.uint8)
pixels.auto_write = True
while True:
pixels[:] = palette[heart].flatten()
heart += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment