Skip to content
This repository was archived by the owner on Aug 3, 2025. It is now read-only.

Commit a582fab

Browse files
author
root
committed
Merge branch 'master' of git://github.com/acm-uiuc/chroma-scripts
2 parents 110b0d3 + 7ddf597 commit a582fab

File tree

4 files changed

+125
-89
lines changed

4 files changed

+125
-89
lines changed

animations/boxy/main.py

Lines changed: 79 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,29 @@
33
import random
44
import math
55
import time
6-
from animations import FadeAnimation
6+
from animations import FadeAnimation
77

8-
#author: Harsh Singh
8+
# author: Harsh Singh
9+
light_count = 48
910
nice_pixels = [
10-
(1023.0,0.0,0.0),
11-
(0.0,1023.0,0.0),
12-
(0.0,0.0,1023.0),
13-
(0.0,1023.0,1023.0),
14-
(1023.0,0.,1023.0),
15-
(1023.0,1023.0,0.),
16-
(823.0,823.0,0.0),
17-
(823.0,0.0,823.0),
18-
(0.0,823.0,823.0),
11+
(1023.0, 0.0, 0.0),
12+
(0.0, 1023.0, 0.0),
13+
(0.0, 0.0, 1023.0),
14+
(0.0, 1023.0, 1023.0),
15+
(1023.0, 0., 1023.0),
16+
(1023.0, 1023.0, 0.),
17+
(823.0, 823.0, 0.0),
18+
(823.0, 0.0, 823.0),
19+
(0.0, 823.0, 823.0),
1920
]
20-
bgColor=(0.0,0.0,0.0)
21-
template = [[0,1,4,5],[2,3,6,7],[8,9,12,13],[10,11,14,15],[16,17,20,21],[18,19,22,23],[0,1,2,3,4,7,8,11,12,13,14,15],[5,6,9,10],]
21+
bgColor = (0.0, 0.0, 0.0)
22+
template = [
23+
[0, 1, 4, 5], [2, 3, 6, 7], [8, 9, 12, 13], [
24+
10, 11, 14, 15], [16, 17, 20, 21],
25+
[18, 19, 22, 23], [0, 1, 2, 3, 4, 7, 8, 11, 12, 13, 14, 15], [5, 6, 9, 10], ]
2226
out = FadeAnimation()
2327
out.start()
24-
layout = [bgColor]*24
28+
layout = [bgColor] * light_count
2529

2630

2731
def repeat(**options):
@@ -30,124 +34,130 @@ def repeat(**options):
3034
if (options.get("times") > 1):
3135
times = options.get("times")
3236
if (options.get("frames")):
33-
while (n<times):
37+
while (n < times):
3438
options.get("frames")
35-
n+=1
39+
n += 1
3640

3741
# set color in box 1,2,3,4 with .4 second interval
42+
43+
3844
def frame1():
39-
rand = random.sample(nice_pixels,5)
40-
layout = [rand[4]]*24
45+
rand = random.sample(nice_pixels, 5)
46+
layout = [rand[4]] * light_count
4147
out.write(layout)
42-
time.sleep(0.4)
43-
for i in [0,1,3,2]:
48+
time.sleep(0.4)
49+
for i in [0, 1, 3, 2]:
4450
for j in range(4):
4551
layout[template[i][j]] = rand[i]
46-
#printlayout(layout)
52+
# printlayout(layout)
4753
out.write(layout)
4854
time.sleep(0.4)
4955

5056

5157
# set color outer box, then inner box .2 delay
5258
def frame2():
53-
rand = random.sample(nice_pixels,3)
54-
layout = [rand[2]]*24
55-
for i in [6,7]:
59+
rand = random.sample(nice_pixels, 3)
60+
layout = [rand[2]] * light_count
61+
for i in [6, 7]:
5662
for j in range(len(template[i])):
57-
layout[template[i][j]] = rand[i-6]
63+
layout[template[i][j]] = rand[i - 6]
5864
out.write(layout)
5965
time.sleep(0.2)
6066

6167

62-
63-
6468
# spin colors at 5,6,9,10 at .1 second interval
6569
def frame3():
66-
rand = random.sample(nice_pixels,5)
67-
layout = [rand[4]]*24
68-
#printlayout(layout)
69-
#out.write(layout)
70-
#time.sleep(0.4)
71-
i = 0
70+
rand = random.sample(nice_pixels, 5)
71+
layout = [rand[4]] * light_count
72+
# printlayout(layout)
73+
# out.write(layout)
74+
# time.sleep(0.4)
75+
i = 0
7276
for j in range(len(template[i])):
7377

74-
#print "i= "+str(i)+" j ="+str(j)
78+
# print "i= "+str(i)+" j ="+str(j)
7579
layout[template[7][j]] = rand[i]
7680
out.write(layout)
7781
time.sleep(0.1)
78-
i+=1
79-
#printlayout(layout)
80-
82+
i += 1
83+
# printlayout(layout)
84+
8185
# spin colors at 5,6,9,10 at .1 second interval
86+
87+
8288
def frame3():
83-
rand = random.sample(nice_pixels,5)
84-
layout = [rand[4]]*24
85-
#printlayout(layout)
86-
#out.write(layout)
87-
#time.sleep(0.4)
88-
i = 0
89+
rand = random.sample(nice_pixels, 5)
90+
layout = [rand[4]] * light_count
91+
# printlayout(layout)
92+
# out.write(layout)
93+
# time.sleep(0.4)
94+
i = 0
8995
for j in range(len(template[i])):
9096

91-
#print "i= "+str(i)+" j ="+str(j)
97+
# print "i= "+str(i)+" j ="+str(j)
9298
layout[template[7][j]] = rand[i]
9399
out.write(layout)
94100
time.sleep(0.1)
95-
i+=1
96-
#printlayout(layout)
101+
i += 1
102+
# printlayout(layout)
103+
104+
# spiral function from 0 to 9
105+
97106

98-
#spiral function from 0 to 9
99107
def frame4():
100-
path = [0,1,2,3,7,11,15,14,13,12,8,4,5,6,10,9]
101-
102-
rand = random.sample(nice_pixels,4)
108+
path = [0, 1, 2, 3, 7, 11, 15, 14, 13, 12, 8, 4, 5, 6, 10, 9]
109+
110+
rand = random.sample(nice_pixels, 4)
103111
for i in range(len(path)):
104112
layout[path[i]] = rand[0]
105113
if (i != 0):
106-
layout[path[i-1]] = rand[1]
114+
layout[path[i - 1]] = rand[1]
107115
# else:
108116
# layout[path[len(path)-1]] = rand[1]
109-
#printlayout(layout)
117+
# printlayout(layout)
110118
out.write(layout)
111119
time.sleep(0.05)
112120
for i in range(len(path)):
113-
layout[path[len(path)-1-i]] = rand[2]
121+
layout[path[len(path) - 1 - i]] = rand[2]
114122
if (i != 0):
115-
layout[path[len(path)-i]] = rand[3]
123+
layout[path[len(path) - i]] = rand[3]
116124
# else:
117125
# layout[path[len(path)-1]] = rand[1]
118-
#printlayout(layout)
126+
# printlayout(layout)
119127
out.write(layout)
120128
time.sleep(0.05)
121129

130+
122131
def color_picker():
123-
r = random.random()*1000
132+
r = random.random() * 1000
124133
b, g = (0., 0.)
125134
while True:
126135
if (b > 1000):
127-
r = random.random()*1000
136+
r = random.random() * 1000
128137
b = 0
129-
g = random.random()*1000
138+
g = random.random() * 1000
130139
if (g > 1000):
131-
r = random.random()*1000
132-
b = random.random()*1000
140+
r = random.random() * 1000
141+
b = random.random() * 1000
133142
g = 0
134143
if (r > 1000):
135-
g = random.random()*1000
136-
b = random.random()*1000
144+
g = random.random() * 1000
145+
b = random.random() * 1000
137146
r = 0
138147

139-
r+= 10.
140-
b+= 10.
141-
g+= 10.
142-
layout = [(r,g,b)]*24
143-
print (r,g,b)
148+
r += 10.
149+
b += 10.
150+
g += 10.
151+
layout = [(r, g, b)] * light_count
152+
print (r, g, b)
144153
out.write(layout)
145154
time.sleep(.01)
146155

147156

148157
def printlayout(layout):
149-
for i in range(0,5):
150-
print (str(layout[i*4+0])+ " " +str(layout[i*4+1])+ " " +str(layout[i*4+2])+ " " +str(layout[i*4+3]))
158+
for i in range(0, 5):
159+
print (str(layout[i * 4 + 0]) + " " + str(layout[i * 4 + 1])
160+
+ " " + str(layout[i * 4 + 2]) + " " + str(layout[i * 4 + 3]))
151161
print
152162

153163
if __name__ == "__main__":

animations/spirals/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
bgColor=(0.0,0.0,0.0)
1616
out = FadeAnimation()
1717
out.start()
18-
layout = [bgColor]*24
18+
light_count = 48
19+
layout = [bgColor]* light_count
1920

2021
"""
2122
Spirals! Start from 0-3,3-15,15-12,12-4,4-6,6-10,10-9, then do it in reverse
@@ -43,7 +44,7 @@ def spirals():
4344
"""
4445

4546
def blinky():
46-
layout = [bgColor]*24
47+
layout = [bgColor]* light_count
4748

4849
rand = random.sample(nice_pixels,2)
4950
for i in template[len(template)-2]:
@@ -55,11 +56,11 @@ def blinky():
5556
out.write(layout)
5657
time.sleep(0.3)
5758
temp = layout
58-
layout = [bgColor]*24
59+
layout = [bgColor]* light_count
5960
#recycle code later
6061
# for i in range(3):
6162
# if (i%2 == 0):
62-
# layout = [bgColor]*24
63+
# layout = [bgColor]* light_count
6364
# else :
6465
# layout = temp
6566
# out.write(layout)

animations/traffic/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
scale = 1
1717
out = FadeAnimation()
1818
out.start()
19+
light_count = 48
1920

2021

2122
def frame1():
2223
scale = random.randint(1,4)
23-
layout = [nice_pixels[0]]*24
24+
layout = [nice_pixels[0]]*light_count
2425
out.write(layout)
2526
time.sleep(3*scale)
26-
layout = [nice_pixels[1]]*24
27+
layout = [nice_pixels[1]]*light_count
2728
out.write(layout)
2829
time.sleep(5*scale)
29-
layout = [nice_pixels[2]]*24
30+
layout = [nice_pixels[2]]*light_count
3031
out.write(layout)
3132
time.sleep(1*scale)
3233

animations/well/main.py

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,48 @@
66
from animations import FadeAnimation
77
import operator
88

9+
#NOTE: This is some pretty shitty code i hacked up. Don't use it as an example, still a work in progress
10+
911
#author: Harsh Singh
10-
red = (1023.0,0.0,0.0)
11-
yello = (1023.0,1023.0,0)
12+
cool_trans = [[(1023.0,0.0,0.0),(1023.0,1023.0,0)], [(0.0,0.0,1023.0),(1023.0,0,1023.0)]]
1213

1314
bgColor=(0.0,0.0,0.0)
1415
layout = [[bgColor for col in range(4)] for row in range(4)]
1516
out = FadeAnimation()
1617
out.start()
18+
times = 30
1719

18-
def well():
20+
def well(col1, col2):
1921
global layout
20-
times = 40
22+
23+
for a in xrange(times):
24+
set_layout(col1, col2, a, times)
25+
out.write(makeLayout(layout))
26+
time.sleep(.05)
27+
for a in xrange(times):
28+
set_layout(col2, col1, a, times)
29+
out.write(makeLayout(layout))
30+
time.sleep(.05)
31+
32+
def fade_out():
2133
for a in xrange(times):
2234
for x in xrange(4):
2335
for y in xrange(4):
24-
if (0<x<3 and 0<y<3):
25-
layout[x][y] = transition_color(red, yello, a, times)
26-
else:
27-
layout[x][y] = transition_color(yello, red, a, times)
36+
layout[x][y] = transition_color(layout[x][y], bgColor, a, times)
2837
out.write(makeLayout(layout))
2938
time.sleep(.05)
39+
40+
def fade_in():
41+
3042
for a in xrange(times):
3143
for x in xrange(4):
3244
for y in xrange(4):
33-
if (0<x<3 and 0<y<3):
34-
layout[x][y] = transition_color(yello, red, a, times)
35-
else:
36-
layout[x][y] = transition_color(red, yello, a, times)
45+
layout[x][y] = transition_color(bgColor, layout[x][y], a, times)
46+
printLayout(layout)
3747
out.write(makeLayout(layout))
3848
time.sleep(.05)
3949

50+
4051
def transition_color(col1, col2, step, steps):
4152
step +=1
4253
col1 = tuple( [ int( e- (e * step/steps) ) for e in col1 ] )
@@ -55,7 +66,20 @@ def printLayout(lay):
5566
print str(lay[x][0])+" "+str(lay[x][1])+" "+str(lay[x][2])+" "+str(lay[x][3])
5667
print "---------------------------------"
5768

69+
def set_layout(col1, col2, a, times):
70+
71+
for x in xrange(4):
72+
for y in xrange(4):
73+
if (0<x<3 and 0<y<3):
74+
layout[x][y] = transition_color(col1, col2, a, times)
75+
else:
76+
layout[x][y] = transition_color(col2, col1, a, times)
5877

5978
if __name__ == "__main__":
6079
while True:
61-
well()
80+
# well(cool_trans[0][0], cool_trans[0][1])
81+
# fade_out()
82+
# set_layout(cool_trans[1][0], cool_trans[1][1], 4, 4)
83+
# fade_in()
84+
# well(cool_trans[1][0], cool_trans[1][1])
85+
well()

0 commit comments

Comments
 (0)