Skip to content

Instantly share code, notes, and snippets.

@bee-san
Created December 30, 2015 22:54
Show Gist options
  • Save bee-san/242edde599d041c42733 to your computer and use it in GitHub Desktop.
Save bee-san/242edde599d041c42733 to your computer and use it in GitHub Desktop.
Rainbow.py
#!/usr/bin/env python
import unicornhat as unicorn
import time, math, colorsys, random
print("Displaying the rainbows")
unicorn.brightness(0.3)
speed = 0.03
offset = 30
color_check = int(0)
r, g, b = random.randint(1,255), random.randint(1,255), random.randint(1,255)
def cooldown(unicorn):
for y in range(500, 11, -1):
time.sleep(0.001)
if y < 100:
y = "0.0" + str(y)
else:
y = "0." + str(y)
y = float(y)
unicorn.brightness(y)
unicorn.show()
while True:
unicorn.brightness(0.001)
for y in range(8):
for x in range(8):
unicorn.set_pixel(x,y,int(r),int(g),int(b))
for x in range(0, 500):
time.sleep(0.001)
if x < 100:
x = "0.00" + str(x)
else:
x = "0." + str(x)
x = float(x)
unicorn.brightness(x)
unicorn.show()
time.sleep(5)
cooldown(unicorn)
r += 30
if r >= 255:
r = random.randint(1,255)
g += 30
if g >= 255:
g = random.randint(1,255)
b += 30
if b >= 255:
b = random.randint(1,255)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment