-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDomeStarMap.pde
75 lines (63 loc) · 1.85 KB
/
DomeStarMap.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
64
65
66
67
68
69
70
71
72
73
74
75
class DomeStarMap {
class MapEntry {
int x; // x position on dome image
int y; // y position on dome image
float d; // distance to pixel (0.0-1.0)
}
MapEntry[] lookup;
color[] buffer;
public DomeStarMap() {
lookup = new MapEntry[360*360];
buffer = new color[160*40];
this.buildMap();
}
// Builds the lookup table by calculating distance to
// the strip to the left of each point. We step through
// the circle 1/3200th the circumference at a time. It's
// wasteful, but it only has to be done once.
//
// Leaves a 20 pixel buffer at the center of the circle
// to represent the offset of the boxes from the true
// center of the dome.
public void buildMap() {
for (int i=0; i<lookup.length; i++) {
lookup[i] = new MapEntry();
}
for (int i=0; i<3200; i++) {
float radians = TWO_PI/3200*i;
int strip = i/80;
float distance = (1-(i%80/80.0));
for (int j=20; j<180; j++) {
int x = int(180+sin(radians)*j);
int y = int(180+cos(radians)*j);
int led = j-20;
int idx = (y*360+x);
lookup[idx].x = strip;
lookup[idx].y = led;
lookup[idx].d = distance;
}
}
}
// Apply the map by walking the 360x360 image and lerping
// the color of the strip to the left and lerp the inverse
// of the strip on the right.
public color[] applyMap() {
PImage image = get(0,0,360,360);
image.loadPixels();
MapEntry m;
int idx,x;
color c;
for (int i=0; i<image.pixels.length; i++) {
m = lookup[i];
x = m.x;
c = image.pixels[i];
idx = m.y*40+x;
buffer[idx] = lerpColor(buffer[idx],c,m.d);
x++;
if (x>39) x = 0;
idx = m.y*40+x;
buffer[idx] = lerpColor(buffer[idx],c,1.0-m.d);
}
return buffer;
}
}