Skip to content

Commit c35d938

Browse files
author
root
committed
Merge branch 'master' of git://github.com/acm-uiuc/chroma-scripts
2 parents cca765e + cfa84cf commit c35d938

File tree

15 files changed

+226
-200
lines changed

15 files changed

+226
-200
lines changed

animations/boxy/main.py

Lines changed: 0 additions & 168 deletions
This file was deleted.

animations/boxy/manifest.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

animations/cylon/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
while True:
1313
pix = []
1414
alive = 0
15-
if n == 3:
15+
if n == 5:
1616
direction = -1
1717
elif n == 0:
1818
direction = 1
19-
for i in xrange(6):
20-
for j in xrange(4):
19+
for i in xrange(8):
20+
for j in xrange(6):
2121
if j == n:
2222
pix.append((1023.0,0.0,0.0))
2323
else:

animations/image-cycle/main.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
from math import sqrt
2+
from animations import FadeAnimation
3+
import requests
4+
from PIL import Image
5+
from StringIO import StringIO
6+
from time import sleep
7+
from collections import namedtuple
8+
Color = namedtuple("Color", ["r","g", "b"])
9+
# author: Harsh Singh
10+
light_count = 48
11+
rows = 8
12+
cols = 6
13+
out = FadeAnimation()
14+
out.FADEINRATE = 2 # optional
15+
out.FADEOUTRATE = 8 # optional, makes things 'trail off'
16+
out.start()
17+
18+
pix = [(1023.0, 0.0, 0.0)] * light_count
19+
20+
21+
class ImagePoint(object):
22+
23+
"""docstring for Point"""
24+
25+
def __init__(t, size, rows, cols, x=0, y=0):
26+
super(ImagePoint, t).__init__()
27+
t.x = x
28+
t.y = y
29+
t.rows = rows
30+
t.cols = cols
31+
t.size_x, t.size_y = size
32+
t.done = False
33+
t.direction = "right"
34+
35+
def move_down(t):
36+
print "called down"
37+
t.direction = "down"
38+
t.down_count = 0
39+
t.move()
40+
41+
def move(t):
42+
if t.direction is "right":
43+
if t.x == t.size_x - t.cols - 1:
44+
t.next_direction = "left"
45+
t.move_down()
46+
else:
47+
t.x += 1
48+
elif t.direction is "left":
49+
if t.x - 1 < 0:
50+
t.next_direction = "right"
51+
t.move_down()
52+
else:
53+
t.x -= 1
54+
elif t.direction is "down":
55+
if t.y is t.size_y:
56+
if t.last_row:
57+
t.done = True
58+
t.last_row = True
59+
t.direction = t.next_direction
60+
elif t.down_count + 1 is t.rows:
61+
# change rows to 2 condition for less jumpy
62+
t.direction = t.next_direction
63+
else:
64+
t.down_count += 1
65+
t.y += 1
66+
67+
def similar_frame(t, img_data):
68+
# http://stackoverflow.com/questions/8863810/python-find-similar-colors-best-way
69+
a = Color(*img_data[t.x, t.y])
70+
b = Color(*img_data[t.x + t.cols-1, t.y])
71+
rm = 0.5*(a.r+b.r)
72+
return abs(((2+rm) * (a.r-b.r)**2) + 4*(a.g-b.g)**2 + ((3-rm) * (a.b-b.b)**2))**.5 < 10
73+
74+
def write_frame(t, out, img_data):
75+
"""
76+
Given a frame larger than grid size, select only values starting from top left to fit grid
77+
"""
78+
result = [rgb_to_lights(img_data[t.x + i, t.y + j]) for i in xrange(t.cols) for j in xrange(t.rows)]
79+
out.write(result)
80+
81+
82+
def longest_side():
83+
return max(rows, cols)
84+
85+
86+
def get_image():
87+
url = "https://api.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=88a7df8d4b7696c5de97f5fc97c75c91&format=json&nojsoncallback=1"
88+
recent_image = requests.get(url).json()["photos"]["photo"][0]
89+
picture_url = "http://farm{farm_id}.staticflickr.com/{server_id}/{id}_{secret}.jpg".format(
90+
farm_id=recent_image["farm"], server_id=recent_image["server"], id=recent_image["id"], secret=recent_image["secret"])
91+
img = Image.open(StringIO(requests.get(picture_url).content))
92+
return img
93+
94+
def rgb_to_lights(rgb):
95+
return [i * 4.0 for i in rgb]
96+
97+
def animation_picture_slider():
98+
img = get_image()
99+
size = img.size
100+
img_data = img.load()
101+
speed = .15
102+
point = ImagePoint(size, rows, cols)
103+
while (not point.done):
104+
point.write_frame(out, img_data)
105+
point.move()
106+
if point.similar_frame(img_data):
107+
if speed > .01:
108+
speed *= .9
109+
elif speed < .16:
110+
speed *=1.04
111+
sleep(speed)
112+
113+
114+
if __name__ == "__main__":
115+
while True:
116+
animation_picture_slider()

animations/image-cycle/manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name":"Image Cycle",
3+
"description":"Get cool images from flikr and run through them with varying speed",
4+
"creator":"Harsh Singh (@Harsh Singh)"
5+
}

animations/light-dance/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
if __name__ == "__main__":
77
import time
88
out = ColorsOut()
9-
pix = [(0.0,0.0,0.0)] * 24
9+
pix = [(0.0,0.0,0.0)] * 48
1010
fallRate = 7.0
1111
sleepTimer = 0.02
1212
frameMax = 40
1313
frames = 0
14-
for i in xrange(24):
14+
for i in xrange(48):
1515
pix[i] = (0.0 , 0.0, 0.0)
1616

1717
while True:
1818
if frames < 0:
19-
pix[random.randint(0, 23.0)] = (1023.0, 1023.0, 1023.0)
19+
pix[random.randint(0, 47.0)] = (1023.0, 1023.0, 1023.0)
2020
frames = random.randint(0, frameMax)
2121

2222
else:
2323
frames = frames - 1
2424

2525
out.write(pix)
2626

27-
for i in xrange(24):
27+
for i in xrange(48):
2828
pix[i] = (pix[i][0] - fallRate, pix[i][1] - fallRate, pix[i][2] - fallRate)
2929

30-
time.sleep(sleepTimer)
30+
time.sleep(sleepTimer)

0 commit comments

Comments
 (0)