Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
import time
import random
import colorsys
import numpy as np
import rainbowhat as rainbow
rainbow.rotation(0)
rainbow.brightness(1.0)
WIDTH, NUM_PIXELS = rainbow.get_shape()
start = 0
end = 60
while True:
for py in random.sample(([x for x in range(WIDTH)]), WIDTH):
wait = np.random.choice(
np.random.noncentral_chisquare(5, 1, 1000), 1)[0] / 5000
n = np.random.choice(np.random.noncentral_chisquare(5, 0.1, 1000), 1)
limit = int(n[0])
if limit > NUM_PIXELS:
limit = NUM_PIXELS
for px in range(NUM_PIXELS):
if px > limit:
r, g, b = 0, 0, 0
else:
hue = start + (((end - start) / float(NUM_PIXELS)) * px)
r, g, b = [int(c * 255)
for c in colorsys.hsv_to_rgb(hue / 360.0, 1.0, 1.0)]
if py % 2 != 0:
py -= 1
px = (7 - (px+4)) + 4
rainbow.set_pixel(px, py/2, r, g, b)
rainbow.show()
time.sleep(0.01 / (px + 1))
time.sleep(wait)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.