forked from IzzyBrand/ledvis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmasker.py
97 lines (82 loc) · 3.18 KB
/
masker.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import numpy as np
from config import *
def bottom_up(m, channel):
'''
Creates a mask of which leds to turn on given an amplitude.
This mask lights a strip of LEDs starting at the bottom and reaching higher
with increasing amplitude
Arguments:
m (float): The amplitude in 0 to 1
Returns:
A [LED_1_COUNT x 3] array of zeros and ones
'''
if channel == 1:
num_leds_on = m * LED_1_COUNT
return np.tile(np.arange(LED_1_COUNT) < num_leds_on, (3,1)).T
elif channel == 2:
num_leds_on = m * LED_2_COUNT
return np.tile(np.arange(LED_2_COUNT) < num_leds_on, (3,1)).T
def bottom_upV(m, channel):
'''
Creates a mask of which leds to turn on given an amplitude.
This mask lights a strip of LEDs starting at the bottom and reaching higher
with increasing amplitude
Arguments:
m (float): The amplitude in 0 to 1
Returns:
A [LED_1_COUNT] array of zeros and ones
'''
if channel == 1:
num_leds_on = m * LED_1_COUNT
return np.tile(np.abs(np.arange(LED_1_COUNT/3)) < num_leds_on/3-0.01, (3,1)).T
elif channel == 2:
num_leds_on = m * LED_2_COUNT
return np.tile(np.abs(np.arange(LED_2_COUNT/3)) < num_leds_on/3-0.01, (3,1)).T
def top_down(m, channel):
'''
Creates a mask of which leds to turn on given an amplitude.
This mask lights a strip of LEDs starting at the top and reaching lower
with increasing amplitude
Arguments:
m (float): The amplitude in 0 to 1
Returns:
A [LED_1_COUNT x 3] array of zeros and ones
'''
if channel == 1:
num_leds_on = m * LED_1_COUNT
return np.tile(LED_1_COUNT - np.arange(LED_1_COUNT) < num_leds_on, (3,1)).T
elif channel == 2:
num_leds_on = m * LED_2_COUNT
return np.tile(LED_2_COUNT - np.arange(LED_2_COUNT) < num_leds_on, (3,1)).T
def middle_out(m, channel):
'''
Creates a mask of which leds to turn on given an amplitude.
This mask lights a strip of LEDs starting at the middle and reaching out
with increasing amplitude
Arguments:
m (float): The amplitude in 0 to 1
Returns:
A [LED_1_COUNT x 3] array of zeros and ones
'''
if channel == 1:
num_leds_on = m * LED_1_COUNT
return np.tile(np.abs(LED_1_COUNT/2.0 - np.arange(LED_1_COUNT)) < num_leds_on/2., (3,1)).T
elif channel == 2:
num_leds_on = m * LED_2_COUNT
return np.tile(np.abs(LED_2_COUNT/2.0 - np.arange(LED_2_COUNT)) < num_leds_on/2., (3,1)).T
def clamp(m, channel):
'''
Creates a mask of which leds to turn on given an amplitude.
This mask lights a strip of LEDs starting at the top and bottom and reaching towards
the middle with increasing amplitude
Arguments:
m (float): The amplitude in 0 to 1
Returns:
A [LED_1_COUNT x 3] array of zeros and ones
'''
if channel == 1:
num_leds_on = (1. - m) * LED_1_COUNT
return 1 - np.tile(np.abs(LED_1_COUNT/2.0 - np.arange(LED_1_COUNT)) < num_leds_on/2., (3,1)).T
elif channel == 2:
num_leds_on = (1. - m) * LED_2_COUNT
return 1 - np.tile(np.abs(LED_2_COUNT/2.0 - np.arange(LED_2_COUNT)) < num_leds_on/2., (3,1)).T