blob: e7e7481041a4346f1ab2da6b3d9f99c6d2964b3f (
plain) (
blame)
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
|
from luxcena_neo import NeoBehaviour, FloatVariable
from time import perf_counter
def wheel(pos):
"""Generate rainbow colors across 0-255 positions."""
if pos < 85:
return (pos * 3, 255 - pos * 3, 0)
elif pos < 170:
pos -= 85
return (255 - pos * 3, 0, pos * 3)
else:
pos -= 170
return (0, pos * 3, 255 - pos * 3)
class Main(NeoBehaviour):
def declare_variables(self):
self.declare(FloatVariable("speed", 1, min_val=1, max_val=6, step=0.1))
def on_start(self):
""" Execute when mode is selected. """
self.i = 0
self.last_inst = perf_counter()
def each_tick(self):
if (perf_counter() - self.last_inst) > (6-self.var.speed):
self.i += 1
if self.i > 255: self.i = 0
for i in range(strip.num_pixels()):
strip.set_pixel_color(i, wheel(self.i))
strip.show()
self.last_inst = perf_counter()
|