-
Notifications
You must be signed in to change notification settings - Fork 10
/
tracks.pde
207 lines (160 loc) · 6.16 KB
/
tracks.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// the main track object holds a collection of points
class Tracks {
int pointCount;
float X[];
float Y[];
float Z[];
float[] speed;
String[] time;
int pointTracer = 0;
// constructor
Tracks(int num) {
pointCount = num;
X = new float[pointCount];
Y = new float[pointCount];
Z = new float[pointCount];
speed = new float[pointCount];
time = new String[pointCount];
}
void render() {
strokeWeight(2);
for (int i = 1; i < pointCount; i++) {
// make sure this wasn't a skipped point in the data
// (has the unfortunate side effect of breaking routes taking place at 0,0, but
// considering that's a few hundred km off the coast of Gabon, I'm okay with that)
if (X[i] != 0) {
float speedLimit = findDifference(scene.maxSpeed, scene.minSpeed) / 5;
switch(scene.viewMode) {
// plain white
case 0:
stroke(scene.palette[1], 60);
noFill();
if (X[i - 1] != 0) {
drawConnectors(X[i - 1], Y[i - 1], Z[i - 1], X[i], Y[i], Z[i]);
}
break;
// elevation indicators:
// red for the high elevations, blue for the low
case 1:
float heightLimit = findDifference(scene.maxY, scene.minY) / 11;
for (int j = 0; j < 20; j++) {
if (Y[i] > (j * 0.9 * heightLimit)) {
stroke(j * 12, 0, 255 - j * 12, 255);
}
}
noFill();
if (X[i - 1] != 0) {
drawConnectors(X[i - 1], Y[i - 1], Z[i - 1], X[i], Y[i], Z[i]);
}
break;
// speed indicators: a manual spectrum from dark blue to red
case 2:
if (speed[i] > 0) {stroke(0, 0, 255, 32);} // faded blue
if (speed[i] > 10) {stroke(0, 0, 255, 128);} // full blue
if (speed[i] > 20) {stroke(0, 255, 0, 128);} // green
if (speed[i] > 25) {stroke(255, 255, 0, 128);} // yellow
if (speed[i] > 30) {stroke(255, 192, 0, 128);} // yellow orange
if (speed[i] > 35) {stroke(255, 128, 0, 128);} // orange
if (speed[i] > 40) {stroke(255, 64, 0, 128);} // orange red
if (speed[i] > 50) {stroke(255, 0, 0, 128);} // dark red
if (speed[i] > 60) {stroke(255, 0, 0, 192);} // less dark red
if (speed[i] > 70) {stroke(255, 0, 0, 255);} // red
if (speed[i] > 80) {stroke(255, 255, 255, 255);} // white
noFill();
if (X[i - 1] != 0) {
drawConnectors(X[i - 1], Y[i - 1], Z[i - 1], X[i], Y[i], Z[i]);
}
break;
// animated tracers
case 3:
noStroke();
noFill();
color strokeColor = color(0, 0, 255);
stroke(strokeColor, 48);
// create the fadeout trails
for (int j = 0; j < 64; j++) {
if (i == pointTracer - j) {stroke(strokeColor, 128 - 2 * j);}
}
// more strongly define the current point
if (i == pointTracer) {stroke(strokeColor, 255);}
if (X[i - 1] != 0) {
drawConnectors(X[i - 1], Y[i - 1], Z[i - 1], X[i], Y[i], Z[i]);
}
break;
// elevation spikes
case 4:
noFill();
stroke(scene.palette[1], 32);
drawConnectors(X[i], scene.minY, Z[i], X[i], Y[i], Z[i]);
drawConnectors(X[i - 1], scene.minY, Z[i - 1], X[i], scene.minY, Z[i]);
drawConnectors(X[i - 1], Y[i - 1], Z[i - 1], X[i], Y[i], Z[i]);
break;
} // end switch
} //end if
} // end for
pointTracer++;
if (pointTracer > pointCount) {
pointTracer = 0;
}
} // end render()
void getDimensions() {
// loop through all points and find the ranges
for (int i = 1; i < pointCount; i++) {
scene.minX = checkMe(scene.minX, X[i], "min");
scene.maxX = checkMe(scene.maxX, X[i], "max");
scene.minY = checkMe(scene.minY, Y[i], "min");
scene.maxY = checkMe(scene.maxY, Y[i], "max");
scene.minZ = checkMe(scene.minZ, Z[i], "min");
scene.maxZ = checkMe(scene.maxZ, Z[i], "max");
scene.minSpeed = checkMe(scene.minSpeed, speed[i], "min");
scene.maxSpeed = checkMe(scene.maxSpeed, speed[i], "max");
}
// move the scene center point to 0, 0
scene.offsetX = 0 - (scene.minX + findDifference(scene.minX, scene.maxX));
scene.offsetY = 0 - (scene.minY + findDifference(scene.minY, scene.maxY));
scene.offsetZ = 0 - (scene.minZ + findDifference(scene.minZ, scene.maxZ));
// math to compensate for latitude distortion
// adapted from http://msdn.microsoft.com/en-us/library/bb259689.aspx
scene.currentWidth = findDifference(scene.minZ, scene.maxZ) * 2 * cos(scene.averageLat * PI/180);
scene.currentHeight = findDifference(scene.minX, scene.maxX) * 2 * cos(scene.averageLat * PI/180);
setSceneScale();
}
void drawConnectors(float x1, float y1, float z1, float x2, float y2, float z2) {
// flatten out the Y axis if we're in 2D mode
if (scene.viewDimension == "2D") {
y1 = 0;
y2 = 0;
}
// check viewConnectors and draw lines or points, respectively
if (scene.viewConnectors) {
line(
x1, y1 * scene.elevationExaggeration, z1,
x2, y2 * scene.elevationExaggeration, z2
);
} else {
point(x2, y2 * scene.elevationExaggeration, z2);
}
}
float checkMe(float val, float iteration, String dir) {
// if the value hasn't been set yet, lets initialize it
if (val == 0) {
val = iteration;
} else {
// if we're looking for a minimum, see if the current value is lower than the current minimum
if (dir == "min") {
// see the note above re:Gabon for the reason why this check is necessary
if (iteration != 0) {
if (iteration < val) {
val = iteration;
}
}
// otherwise see if the current value is higher than the current maximum
} else {
if (iteration > val) {
val = iteration;
}
}
}
return val;
}
}