-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrobe_wheel.py
executable file
·67 lines (55 loc) · 2.09 KB
/
strobe_wheel.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
65
66
67
#!/usr/bin/env python
from __future__ import print_function
import argparse
PTS = [
(1, 0, 0),
(1, 1, 0),
(0, 1, 0),
(0, 1, 1),
(0, 0, 1),
(1, 0, 1),
]
def interpolate(pt_a, pt_b, wt_a):
return tuple(a * wt_a + b * (1 - wt_a) for a, b in zip(pt_a, pt_b))
def scale(pt, scal):
return tuple(int(a * scal) for a in pt)
def opposite(pt):
return (1-pt[0], 1-pt[1], 1-pt[2])
def color_wheel(steps):
steps_per_point = steps / len(PTS)
cur_point = 0
for idx in range(steps):
incr = idx % steps_per_point
if incr == 0:
cur_point += 1
if cur_point >= len(PTS):
# wrap around
pt_a = PTS[cur_point - 1]
pt_b = PTS[0]
else:
pt_a = PTS[cur_point - 1]
pt_b = PTS[cur_point]
wt_a = float(steps_per_point - incr) / steps_per_point
yield interpolate(pt_a, pt_b, wt_a)
def strobe_wheel(steps, step_length, brightness, leds):
l1 = list(color_wheel(steps * len(PTS)))
l2 = list(color_wheel(steps * len(PTS)))
l2 = l2[len(l2)//2:] + l2[:len(l2)//2]
l = [x for pair in zip(l1, l2) for x in pair]
for point in l:
print(step_length, 0,
' '.join(
[' '.join(str(x) for x in scale(point, brightness)) for i in range(leds)]
)
)
print('END')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Create a color wheel animation")
parser.add_argument("--steps", type=int, default=64,
help="How many steps should each point in the color wheel get?")
parser.add_argument("--step-length", type=int, default=1,
help="How many frames should each step be? (hint: use --steps instead)")
parser.add_argument("--brightness", type=int, default=20, help="Maximum brightness per channel (0-255)")
parser.add_argument("--leds", type=int, default=4, help="How many LEDs to generate channels for? (def 4)")
args = parser.parse_args()
strobe_wheel(args.steps, args.step_length, args.brightness, args.leds)