-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchlights_remote.py
60 lines (47 loc) · 2.53 KB
/
searchlights_remote.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
import random
import time
import os
import sys
file_dir = os.path.dirname(__file__)
sys.path.append(file_dir)
from base_remote_strip import BaseRemoteStrip
from base_remote_strip import MidiTransform
from base_remote_strip import NumberUtils
from base_remote_strip import ColorMidiUtils
from bibliopixel import colors as bp_colors
class SearchlightsRemote(BaseRemoteStrip):
def __init__(self, layout, colors=[], tail=2, start=0, end=-1, **args):
super(SearchlightsRemote, self).__init__(layout, start, end, **args)
self._colors = colors
self._tail = tail
def pre_run(self):
self._direction = [1, 1, 1]
self._currentpos = [0, 0, 0]
self._steps = [1, 1, 1]
self._fadeAmt = 256 / self._tail
def step(self, amt=1):
self._tail = int(MidiTransform.remap_cc_value(self.count_control, 2, self._size))
hue = int(MidiTransform.remap_cc_value(self.color_control, 1, 255))
hues = bp_colors.hue_gradient(0, hue, 3)
self._colors = list(map(lambda x: bp_colors.hue2rgb(x), hues))
self._ledcolors = [(0, 0, 0) for i in range(self._size)]
self.layout.all_off()
for i in range(0, 3):
self._currentpos[i] = self._start + self._steps[i]
# average the colors together so they blend
self._ledcolors[self._currentpos[i]] = list(map(lambda x, y: (x + y) // 2, self._colors[i], self._ledcolors[self._currentpos[i]]))
for j in range(1, self._tail):
if self._currentpos[i] - j >= 0:
self._ledcolors[self._currentpos[i] - j] = list(map(lambda x, y: (x + y) // 2, self._ledcolors[self._currentpos[i] - j], bp_colors.color_scale(self._colors[i], 255 - (self._fadeAmt * j))))
if self._currentpos[i] + j < self._size:
self._ledcolors[self._currentpos[i] + j] = list(map(lambda x, y: (x + y) // 2, self._ledcolors[self._currentpos[i] + j], bp_colors.color_scale(self._colors[i], 255 - (self._fadeAmt * j))))
if self._start + self._steps[i] >= self._end:
self._direction[i] = -1
elif self._start + self._steps[i] <= 0:
self._direction[i] = 1
# advance each searchlight at a slightly different speed
self._steps[i] += self._direction[i] * amt * int(random.random() > (i * 0.05))
for i, thiscolor in enumerate(self._ledcolors):
self.layout.set(i, thiscolor)
delay_time = MidiTransform.remap_cc_value(self.delay_control, 0, 1)
time.sleep(delay_time)