-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhalves_rainbow_remote.py
64 lines (52 loc) · 2.13 KB
/
halves_rainbow_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
61
62
63
64
import random
import time
import os
import sys
import math
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 HalvesRainbowRemote(BaseRemoteStrip):
def __init__(self, layout, start=0, end=-1, centre_out=True, rainbow_inc=4, **args):
super(HalvesRainbowRemote, self).__init__(layout, start, end, **args)
self._minLed = 0
self._maxLed = end
if self._maxLed < 0 or self._maxLed < self._minLed:
self._maxLed = self.layout.numLEDs - 1
self._positive = True
self._step = 0
self._centerOut = centre_out
self._rainbowInc = rainbow_inc
def pre_run(self):
self._current = 0
self._step = 0
def step(self, amt=1):
center = float(self._maxLed) / 2
center_floor = math.floor(center)
center_ceil = math.ceil(center)
if self._centerOut:
self.layout.fill(
bp_colors.hue2rgb(self._step), int(center_floor - self._current), int(center_floor - self._current))
self.layout.fill(
bp_colors.hue2rgb(self._step), int(center_ceil + self._current), int(center_ceil + self._current))
else:
self.layout.fill(
bp_colors.hue2rgb(self._step), int(self._current), int(self._current))
self.layout.fill(
bp_colors.hue2rgb(self._step), int(self._maxLed - self._current), int(self._maxLed - self._current))
if self._step == len(bp_colors.conversions.HUE_RAINBOW) - 1:
self._step = 0
else:
self._step += amt + self._rainbowInc
if self._step > len(bp_colors.conversions.HUE_RAINBOW) - 1:
self._step = 0
if self._current == center_floor:
self._current = self._minLed
else:
self._current += amt
delay_time = MidiTransform.remap_cc_value(self.delay_control, 0, 1)
time.sleep(delay_time)