-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMapper.pde
50 lines (40 loc) · 1.25 KB
/
Mapper.pde
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
class MapEntry {
int x;
int y;
int led;
int strip;
public MapEntry(int x, int y, int led, int strip) {
this.x = x;
this.y = y;
this.led = led;
if (Config.STRIP_LOOKUP[strip] >= 0)
this.strip = Config.STRIP_LOOKUP[strip];
else
this.strip = strip;
}
};
class Mapper {
public MapEntry[] build() {
MapEntry[] lookup = new MapEntry[Config.STRIPS * Config.LEDS];
for (int strip = 0; strip < Config.STRIPS; strip++) {
for (int led = 0; led < Config.LEDS; led++) {
float rotation = (float)strip / Config.STRIPS * TWO_PI;
float magnitude = (Config.MAP_PADDING +
(float)led / Config.LEDS * (Config.MAP_WIDTH / 2 - Config.MAP_PADDING));
if (Config.MAP_SWIRL) {
if (led > 16) {
rotation += PI/6 * ((float)led / (Config.LEDS - 16));
}
else {
rotation += PI/6;
}
}
int x = int(Config.MAP_WIDTH / 2 + sin(rotation) * magnitude);
int y = int(Config.MAP_HEIGHT / 2 + cos(rotation) * magnitude);
// TODO Do i need to STRIP_LOOKUP here too?
lookup[led * Config.STRIPS + strip] = new MapEntry(x, y, led, strip);
}
}
return lookup;
}
}