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
|
#!/usr/bin/python3
"""Simple demo of oscillating colors."""
import lumiversepython
import random
import time
def get_all_lights(rig):
"""Return a list of all panels."""
return [rig.select('$panel={}'.format(i)) for i in range(32)]
def restrict(low, x, high):
"""Return a value low <= v <= high, and equal to x if possible."""
return max(low, min(x, high))
def random_change():
"""Return a random amount that a light should change each frame."""
return random.random() / 30
def demo(lights, rig):
"""Do some light things."""
light_status = [
{
'is_increasing': True,
'change': random_change(),
'light': light,
'current_value': 0,
}
for light in lights
]
while True:
for light_s in light_status:
is_increasing = light_s['is_increasing']
change = light_s['change']
light = light_s['light']
current_value = light_s['current_value']
new_value = restrict(
0, current_value + change * (int(is_increasing) * 2 - 1), 1), 1
)
light.setRGBRaw(0, 0, new_value)
light_s['current_value'] = new_value
if new_value == 1:
light_s['is_increasing'] = not is_increasing
light_s['change'] = random_change()
rig.updateOnce()
time.sleep(1 / 60)
def main():
"""Run show."""
rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
rig.init()
lights = get_all_lights(rig)
demo(lights, rig)
if __name__ == '__main__':
main()
|