-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomeStar2Map.pde
63 lines (52 loc) · 1.44 KB
/
DomeStar2Map.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
51
52
53
54
55
56
57
58
59
60
61
62
63
class DomeStar2Map {
int size = width;
int half_size = size / 2;
int strips = 40;
int leds = 160;
int buffer = 20;
class MapEntry {
int x;
int y;
int strip;
int led;
public MapEntry(int x, int y, int strip, int led) {
this.x = x;
this.y = y;
this.strip = strip;
this.led = led;
}
};
MapEntry[] lookup;
color[] pixelBuffer;
public DomeStar2Map() {
lookup = new MapEntry[leds * strips];
pixelBuffer = new color[leds * strips];
this.buildMap();
}
public void buildMap() {
for (int strip = 0; strip < strips; strip++) {
for (int led = 0; led < leds; led++) {
float rotation = (float)strip / strips * TWO_PI;
float magnitude = (buffer + (float)led / leds * (half_size - buffer));
if (led > 16) {
rotation += PI/6 * ((float)led / (leds - 16));
}
else {
rotation += PI/6;
}
int x = int(width / 2 + sin(rotation) * magnitude);
int y = int(width / 2 + cos(rotation) * magnitude);
lookup[led * strips + strip] = new MapEntry(x, y, strip, led);
//point(x,y);
}
}
}
public color[] applyMap() {
PImage image = get();
image.loadPixels();
for (MapEntry entry : lookup) {
pixelBuffer[entry.led * strips + entry.strip] = image.pixels[entry.y * width + entry.x];
}
return pixelBuffer;
}
}