-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.py
77 lines (57 loc) · 2.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys, random
import time
import colorsys
from math import floor
sys.path.append("./osc")
from oscapi import ColorsOut
from animations import FadeAnimation
MAX_BULBS = 48
fps = 60.0
# numerical rate is in % points/second
falloffRate = 12.0 /fps
if __name__ == "__main__":
# writing pixel values every time:
out = ColorsOut()
# yeah I know it's an inefficient use of space, but hey, it's constant space!
hsv = [(0.0,0.0,0.0,0.0)] * MAX_BULBS
# because hsv_to_rgb takes values scaled from 0-1
hsv01 = [(0.0,0.0,0.0)] * MAX_BULBS
# because hsv_to_rgb returns values scaled from 0-1
rgb01 = [(0.0,0.0,0.0)] * MAX_BULBS
# because ColorsOut() is of course, 10-bit rgb
pixOut = [(0.0,0.0,0.0)] * MAX_BULBS
# main loop:
while True:
# using Kevin's "raindrop" algorithm:
# Make some rain
if random.randint(0,5) < 3:
i = random.randint(0,MAX_BULBS -1)
# make so that a pixel never gets replaced by one of lower saturation:
floorOfSat = floor(max(70,hsv[i][1]))
sat = random.randint(floorOfSat,100)
secs = time.localtime().tm_sec
hue = random.gauss(secs * 6.0,5.0) % 360
lum = random.randint(95,100)
fun = 0.0
hsv[i] = (hue,sat,lum,fun)
# make the saturation fall out with time
# (could do something with hue and luminance too):
for i in xrange(MAX_BULBS):
hue = hsv[i][0]
sat = hsv[i][1] - falloffRate
lum = hsv[i][2]
fun = hsv[i][3]
hsv[i] = (hue,sat,lum,fun)
# --------------------------------------------------------------------------
# Everything below this is strictly utilitarian (changing hsv to 10bit rgb):
# --------------------------------------------------------------------------
# Convert from hsv to 10 bit rgb:
for i in xrange(MAX_BULBS):
hue = (hsv[i][0] %360) * 1.0 / 360.0
sat = min(100,abs(hsv[i][1])) * 1.0 / 100.0
lum = min(100,abs(hsv[i][2])) * 1.0 / 100.0
hsv01[i] = (hue,sat,lum)
rgb01[i] = colorsys.hsv_to_rgb(hsv01[i][0],hsv01[i][1],hsv01[i][2])
pixOut[i] = (rgb01[i][0] *1023.0,rgb01[i][1] *1023.0,rgb01[i][2] *1023.0)
out.write(pixOut)
time.sleep(1.0/fps)