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
|
#!/usr/bin/python
"""Simple demo of oscillating colors."""
from __future__ import division
import lumiversepython
import random
import time
FRAME_RATE = 44
MIN_VALUE = 0
MAX_VALUE = 1
MAX_TIME = 4
MIN_TIME = 0.3
def get_all_lights(rig):
"""Return a list of all panels."""
return [rig.select('$side={}[$sequence={}]'.format(j, i)) for j in ['top', 'bot'] for i in range(1, 200)]
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."""
min_time = int(MIN_TIME * FRAME_RATE)
max_time = int(MAX_TIME * FRAME_RATE)
rands = [random.randint(min_time, max_time) for _ in range(5)]
rand_binom = sum(rands) / 5
#inverse = (rand_binom - (MAX_VALUE - MIN_VALUE) / 2) % (MAX_VALUE - MIN_VALUE) + MIN_VALUE
return 1 / random.randint(min_time, max_time)
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(
MIN_VALUE, current_value + change * (int(is_increasing) * 2 - 1), MAX_VALUE
)
light.setRGBRaw(0, 0, new_value)
light_s['current_value'] = new_value
if new_value in [MIN_VALUE, MAX_VALUE]:
light_s['is_increasing'] = not is_increasing
light_s['change'] = random_change()
rig.updateOnce()
time.sleep(1 / FRAME_RATE)
def panels(lights, rig):
for light in lights:
light.setRGBRaw(1, 1, 1)
rig.updateOnce()
time.sleep(1)
light.setRGBRaw(0, 0, 0)
def main():
"""Run show."""
rig = lumiversepython.Rig('/home/teacher/Lumiverse/PBridge.rig.json')
rig.init()
lights = get_all_lights(rig)
demo(lights, rig)
#panels(lights, rig)
if __name__ == '__main__':
main()
|