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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/python
"""Simple demo of oscillating colors."""
from __future__ import division
import color
import colorsys
from DummyRig import DummyRig #import lumiversepython
import math
import random
import time
FRAME_RATE = 10 #44
MIN_VALUE = 0
MAX_VALUE = 1
MAX_TIME = 4
MIN_TIME = 0.3
MAX_HUE = 230 / 360
MIN_HUE = 250 / 360
class Panel(object):
def __init__(self, light):
self.light = light
self.current_color = color.RGB(0, 0, 0)
self.target_color = color.RGB(0, 0, 0)
self.delta = color.RGB(1, 1, 1)
def begin_transition(self, target_color, delta_ticks):
self.target_color = target_color
self.delta = (self.target_color - self.current_color) / delta_ticks
def tick(self):
self.current_color = self.current_color + self.delta
self.light.setRGBRaw(*self.current_color.components)
def transition_complete(self):
return abs(self.current_color - self.target_color) < abs(self.delta)
def get_all_lights(rig):
"""Return a list of all panels."""
return [
Panel(rig.select('$side={}[$sequence={}]'.format(j, i)))
for j in ['top', 'bot'] for i in range(1, 200)
]
def pick_HSV():
"""Return a random color in an appropriate interval."""
hue = random.random() * (MAX_HUE - MIN_HUE) + MIN_HUE
saturation = random.random() * (1 - 0.63) + 0.63
value = random.random()
return color.HSV(hue, saturation, value)
def transition(start, end, step):
"""Return a vector equal to (end - start) * step + start."""
return (end - start) / abs(end - start) * step + start
def random_change():
"""Return a random number of ticks for a light to change"""
min_ticks = int(MIN_TIME * FRAME_RATE)
max_ticks = int(MAX_TIME * FRAME_RATE)
return random.randint(min_ticks, max_ticks)
def demo(lights, rig):
"""Do some light things."""
while True:
print "Tick"
for light in lights:
if light.transition_complete():
if( light == lights[0] ):
print "Transition complete!"
light.begin_transition(pick_HSV().to_RGB(), random_change())
light.tick()
rig.updateOnce()
time.sleep(1 / FRAME_RATE)
def main():
"""Run show."""
rig = DummyRig(200, 2) #lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
rig.init()
lights = get_all_lights(rig)
demo(lights, rig)
if __name__ == '__main__':
main()
|