diff --git a/.gitignore b/.gitignore index e61bca2..1436223 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ # ---> Python +# emacs +*~ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index 6d244a2..ff1cd9b 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ code to drive a light show on the edges of a small stellated dodecahedron, each with a Phillips Hue lightstrip embedded in it. This project depends on the phue package (https://github.com/studioimaginaire/phue) which you should be able to install via `sudo pip3 install phue`. + +Copyright 2019 by Glen Whitney with contributions by others as noted in the code. diff --git a/firestar.py b/firestar.py index a53d579..d0cc668 100644 --- a/firestar.py +++ b/firestar.py @@ -43,7 +43,25 @@ edgecode[29] = 'XX'; edges = [ b[code] for code in edgecode ] -def hueint(frac): return int(frac*65535) +lasthue = 65535 +fullbright = 254 +fullsat = 254 + +# some color preliminaries +white = {'hue' : 0, 'bri' : fullbright, 'sat' : 0} +black = {'bri' : 0, 'sat' : 0} + +def hueint(frac): return int((frac % 1)*lasthue) + +def fshue(frac): + '''Returns a hue number based on the fractional part of frac, warping + [0,1/2) to [0,1/6) and [1/2,1) to [1/2,2/3] + ''' + frac = frac % 1 + if frac < 0.5: return hueint(frac/3); + else: return hueint((frac+1)/3); + +def vivid(hue): return {'hue' : hue, 'bri' : fullbright, 'sat' : fullsat} # A "setting" is a pair of a list of N lists of edges, and a list of N dicts # understandable by Bridge.set_light, @@ -53,10 +71,10 @@ def hueint(frac): return int(frac*65535) # in any list will be left alone. alltogether = [range(0,Nedges)]; -thevoid = (alltogether, ['bri' : 0]) -deepblue = (alltogether, [{'hue' : hueint(2/3), 'bri' : 254, 'sat' : 254}]) -yelorng = (alltogether, [{'hue' : hueint(1/6), 'bri' : 254, 'sat' : 254}]) -redred = (alltogether, [{'hue' : 0, 'bri' : 254, 'sat' : 254}]) +thevoid = (alltogether, [black]) +deepblue = (alltogether, [vivid(hueint(2/3))]) +yelorng = (alltogether, [vivid(hueint(1/6))]) +redred = (alltogether, [vivid(hueint(0))]) # A "simpleshow" is a pair of a list of settings, and a list of triples of # integers: (setting_index, transition_to, hold_time) @@ -68,8 +86,9 @@ redred = (alltogether, [{'hue' : 0, 'bri' : 254, 'sat' : 254}]) intro = ([thevoid, deepblue, yelorng, redred], [(0,1,0), (1,30,20), (2,1,3), (1,1,3), (2,1,3), (1,1,3), (2,1,3), (1,1,3), (2,1,0), - (3,50,20), (0,30,5)] - ) + (3,50,20), (0,30,5)]) + +interlude = ([thevoid], [(0,30,10)]) def runsimple(ss): '''Takes one argument, a simple show; causes the simple show to be @@ -88,3 +107,37 @@ def runsimple(ss): time.sleep(hold_time/10) runsimple(intro) + +# Tour of 5-colorings by Henry Segerman +basehues = {'Red': 0, 'Orange': 5461, 'Yellow': 10923, 'Cyan': 32768, + 'Blue': 43691} + +fivehues = [basehues[c] for c in ['Red', 'Orange', 'Yellow', 'Cyan', 'Blue']] + +fivecolors = [vivid(h) for h in fivehues] + +fivecs = []; + +fivecs.append([[0,22,9,12,25,17], [27,20,10,7,1,15], [26,11,21,8,3,16], + [29,23,13,18,5,2], [28,24,4,6,14,19]]); + +#fivecs.append(([[0,22,9,12,25,17], [27,20,15,24,6,4], [26,11,21,8,3,16], +# [29,23,13,18,5,2], [28,14,19,10,1,7]], fivecolors)); +#fivecs.append(([[12,25,17,8,3,21], [27,20,15,24,6,4], [26,11,16,0,9,22], +# [29,23,13,18,5,2], [28,14,19,10,1,7]], fivecolors)); +#fivecs.append(([[12,17,8,3,28,10], [27,20,15,24,6,4], [26,11,16,0,9,22], +# [29,23,13,18,5,2], [14,19,1,7,25,21]], fivecolors)); +#fivecs.append(([[12,17,8,3,28,10], [27,20,24,4,16,9], [26,11,0,22, ,15,6],[29,23,13,18,5,2],[14,19, 1,7, 25,21]] +# +#"5" +#[[17, 3, 28, 0,6,11],[27,20, 24,4, 16,9],[26, 22, 15, 8,12,10 ],[29,23,13,18,5,#2],[14,19, 1,7, 25,21]] +# +#"6" +#[[17, 3, 28, 0,6,11],[27, 24, 16, 7,19,21],[26, 22, 15, 8,12,10 ],[29,23,13,18,5,2],[14, 1, 25, 4,9,20]] + +exec(open("fivecolor.py").read()) + +runsimple(interlude) +runsimple(jmsshow1) +runsimple(interlude) +runsimple(jmsshow2) diff --git a/fivecolor.py b/fivecolor.py new file mode 100644 index 0000000..3d9e918 --- /dev/null +++ b/fivecolor.py @@ -0,0 +1,38 @@ +### firestar show based on the most symmetric five-coloring +### by John M. Sullivan + +def somecolors(x, n=5, wh=False): + colors = [] + for i in range(0,4): + if i < n: + colors.append(vivid(fshue(x+i/5))) + elif i == n and wh: + colors.append(white) + else: + colors.append(black) + return colors + +jmscolorings1 = [ + somecolors(0,0), somecolors(0,0,True), + somecolors(0,1), somecolors(0,1,True), + somecolors(0,2), somecolors(0,2,True), + somecolors(0,3), somecolors(0,3,True), + somecolors(0,4), somecolors(0,4,True), + somecolors(0) +] + +jmssettings1 = [(fivecs[0], col) for col in jmscolorings1] + +jmsshow1 = (jmssettings1, + [(0,1,2), + (1,1,2),(0,1,2),(1,1,2),(2,1,30), + (3,1,2),(2,1,2),(3,1,2),(4,1,30), + (5,1,2),(4,1,2),(5,1,2),(6,1,30), + (7,1,2),(6,1,2),(7,1,2),(8,1,30), + (9,1,2),(8,1,2),(9,1,2),(10,1,90)]) + +jmscolorings2 = [somecolors(x/120) for x in range(0,119)] +jmssettings2 = [(fivecs[0], col) for col in jmscolorings2] +jmstimings2 = [(n,2,0) for n in range(0,119)] + +jmsshow2 = (jmssettings2, jmstimings2)