Created
November 24, 2015 15:34
-
-
Save iainnash/baf1d24b036ca350a943 to your computer and use it in GitHub Desktop.
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
# coding: utf-8 | |
# In[67]: | |
import serial | |
import time | |
import random | |
ser = serial.Serial('/dev/tty.usbserial-A6007ZJB', 19200) | |
# Execute a command | |
def do(chan, val): | |
ser.write("%dd%dw\n" % (chan, val)) | |
# In[135]: | |
CUBE_RED = 2 | |
CUBE_GREEN = 3 | |
CUBE_BLUE = 1 | |
CUBE_BIG = 4 | |
# In[ ]: | |
# In[100]: | |
do(CUBE_BIG, 0) | |
# In[101]: | |
def cube_color(r,g,b): | |
do(CUBE_RED,r) | |
do(CUBE_GREEN,g) | |
do(CUBE_BLUE,b) | |
# In[ ]: | |
# Maps to different channels | |
CHAN_MAP = { | |
'CUBE_RED': 1, | |
'CUBE_GREEN': 3, | |
'CUBE_BLUE': 2, | |
'CUBE_BIG': 4 | |
} | |
# In[ ]: | |
# In[ ]: | |
# In[155]: | |
# Fade each cube brighter | |
def fade_brighter(cube, timet = 0.01, n = 1): | |
for i in range(0, 255, n): | |
do(cube,i) | |
time.sleep(timet) | |
# Fade each cube dimmer | |
def fade_dimmer(cube, timet = 0.01, n = 1): | |
for i in range(0, 255, n): | |
do(cube, 255-i) | |
time.sleep(timet) | |
# Kills off all the colors so that the center cube is empty | |
def kill_colors(): | |
do(CUBE_RED,0) | |
do(CUBE_BLUE,0) | |
do(CUBE_GREEN,0) | |
do(CUBE_BIG,0) | |
# Fades the inner and outer cubes where the inner cube just fades between red | |
def fade_red(n): | |
for i in range(n): | |
fade_brighter(CUBE_BIG) | |
fade_dimmer(CUBE_RED) | |
fade_dimmer(CUBE_BIG) | |
fade_brighter(CUBE_RED) | |
# Fades the inner and outer cubes where the inner cube is chosen randomly | |
def fade_random(): | |
while True: | |
rand_red = random.randint(0,255) | |
rand_green = random.randint(0,255) | |
rand_blue = random.randint(0,255) | |
fade_brighter(CUBE_BIG) | |
for i in range(rand_red): | |
do(CUBE_RED,255-i) | |
time.sleep(0.01) | |
for i in range(rand_green): | |
do(CUBE_GREEN,255-i) | |
time.sleep(0.01) | |
for i in range(rand_blue): | |
do(CUBE_BLUE,255-i) | |
time.sleep(0.01) | |
fade_dimmer(CUBE_BIG) | |
for i in range(rand_red): | |
do(CUBE_RED,i) | |
time.sleep(0.01) | |
for i in range(rand_blue): | |
do(CUBE_BLUE,i) | |
time.sleep(0.01) | |
for i in range(rand_green): | |
do(CUBE_GREEN,i) | |
time.sleep(0.01) | |
# Alternates flashing between the middle and big cubes | |
def alternate_flash(cube_color, n): | |
if n == 0: | |
while True: | |
do(5, 255) | |
time.sleep(0.1) | |
do(CUBE_GREEN,random.randrange(0, 255)) | |
do(CUBE_BLUE,random.randrange(0, 100)) | |
do(CUBE_RED,random.randrange(0, 255)) | |
fade_brighter(CUBE_BIG, 0.01, 5) | |
time.sleep(0.2) | |
do(5, 0) | |
fade_dimmer(CUBE_BIG, 0.01, 5) | |
kill_colors() | |
do(CUBE_GREEN,0) | |
time.sleep(random.randrange(0, 10)/40.0) | |
else: | |
for i in range(n): | |
time.sleep(0.1) | |
do(CUBE_GREEN,random.randrange(0, 255)) | |
do(CUBE_BLUE,random.randrange(0, 100)) | |
do(CUBE_RED,random.randrange(0, 255)) | |
fade_brighter(CUBE_BIG, 0.01, 15) | |
time.sleep(0.2) | |
fade_dimmer(CUBE_BIG, 0.01, 15) | |
kill_colors() | |
do(CUBE_GREEN,0) | |
time.sleep(random.randrange(0, 10)/40.0) | |
# Concurrently flashes between the middle and big cubes | |
def concurrent_flash(cube_color, n): | |
if n == 0: | |
while True: | |
do(cube_color,0) | |
do(CUBE_BIG,0) | |
time.sleep(0.5) | |
do(cube_color,200) | |
do(CUBE_BIG,200) | |
time.sleep(0.5) | |
else: | |
for i in range(n): | |
do(cube_color,0) | |
do(CUBE_BIG,0) | |
time.sleep(0.5) | |
do(cube_color,200) | |
do(CUBE_BIG,200) | |
time.sleep(0.5) | |
# Concurrently flashes between a random color and the big cubes | |
def concurrent_random_flash(n): | |
if n == 0: | |
while True: | |
kill_colors() | |
time.sleep(0.2) | |
do(CUBE_RED,random.randint(0,255)) | |
do(CUBE_GREEN,random.randint(0,255)) | |
do(CUBE_BLUE,random.randint(0,255)) | |
do(CUBE_BIG,200) | |
time.sleep(0.5) | |
else: | |
for i in range(n): | |
kill_colors() | |
time.sleep(0.2) | |
do(CUBE_RED,random.randint(0,255)) | |
do(CUBE_GREEN,random.randint(0,255)) | |
do(CUBE_BLUE,random.randint(0,255)) | |
do(CUBE_BIG,200) | |
time.sleep(0.5) | |
# Generates random shit | |
def stupid_flash(): | |
time.sleep(0.1) | |
do(CUBE_BIG, 255) | |
for i in range(10): | |
n = random.randint(0, 240) | |
cube_color(n, 240 - n, n) | |
time.sleep(0.006) | |
do(CUBE_BIG, 0) | |
for i in range(10): | |
cube_color(random.randint(0, 240), random.randint(0, 240), random.randint(0, 240)) | |
time.sleep(0.002) | |
kill_colors() | |
while True: | |
alternate_flash(CUBE_RED, 10) | |
cray(2) | |
fade_red(4) | |
#fade_red() | |
#stupid_flash() | |
#concurrent_random_flash(10) | |
#for i in xrange(200): | |
# stupid_flash() | |
# In[152]: | |
while True: | |
do(4, 255) | |
do(5, 255) | |
cube_color(random.randrange(0, 250),random.randrange(0,250),random.randrange(0,250)) | |
time.sleep(0.06) | |
do(4,0) | |
do(5,0) | |
cube_color(0,0,0) | |
time.sleep(0.02) | |
# In[153]: | |
def cray(n): | |
for i in range(n): | |
time.sleep(random.randrange(10, 20)/300.0) | |
do(random.randrange(1, 6), random.randrange(1, 255)) | |
# In[ ]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment