-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemperatureMap.pde
259 lines (205 loc) · 5.92 KB
/
temperatureMap.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Globe
PShape sphere;
// Viewing angles
float angleX = 0;
float angleY = 320;
float zoom = 1;
float speedX = random(5, 50);
float speedY = 0;
float wheelCount = 0;
// Radius of the earth
int rad = 600;
boolean showEarth = true;
boolean showLines = false;
boolean showAll = false;
final int TEMPERATURE = 0;
final int PRESSURE = 1;
final int BOTH = 2;
int drawMode = TEMPERATURE;
float tolerance = 0.15;
// Array of temperature points
TempPoint [] temps;
ArrayList<ArrayList<TempPoint>> tempList;
int res = 2;
void setup() {
fullScreen(P3D);
//size(720, 360, P3D);
// Define the globe
sphere = createShape(SPHERE, rad);
sphere.setTexture(loadImage("Earth.jpg"));
sphere.setStroke(false);
colorMode(HSB);
// Define List of Lists for Antipod finding
tempList = new ArrayList<ArrayList<TempPoint>>();
for (int i = 0; i <= 180*res; i++) {
tempList.add(new ArrayList<TempPoint>());
}
// Load temperatures from JSON
loadTemps("DarkSky4.json");
findTemps();
}
void draw() {
background(51);
pushMatrix();
// Rotate view of whole globe
translate(width/2, height/2, -600);
rotateX(radians(angleY));
rotateY(radians(angleX));
scale(zoom);
// Draw the globe
if (showEarth) shape(sphere);
// Draw each TempPoint
for (ArrayList<TempPoint> l : tempList) {
for (TempPoint t : l) {
t.show();
}
}
//if (angleX != 359) {
// saveFrame("frames/frame-######.tif");
// println("printed!!!");
//} else {
// println("DONE");
// noLoop();
//}
popMatrix();
textSize(width/100);
fill(230);
text("M - Map | T - Temperature | P - Pressure | B - Temperature & Pressure |" +
"L - Lines | Turn Globe with Mouse | A - Show dissimilar Points | J/K change Tolerance",
20, height -20);
if (showLines) {
stroke(255);
strokeWeight(4);
line(0, height/2, width, height/2);
line(width/2, 0, width/2, height);
}
angleX += speedX;
angleY += speedY;
speedX *= 0.9;
speedY *= 0.9;
angleX = angleX % 360;
angleY = angleY % 360;
zoom = constrain(zoom + wheelCount*0.1, 0.01, 2.3*(sqrt((float) width/1920)));
wheelCount = 0.0;
println(zoom);
if (angleX < 0) angleX = 360 - angleX;
if (angleY < 0) angleY = 360 - angleY;
}
void keyPressed() {
switch(keyCode) {
case 77: //m
showEarth = !showEarth;
break;
case 76: // l
showLines = !showLines;
break;
case 84:
drawMode = TEMPERATURE;
break;
case 80:
drawMode = PRESSURE;
break;
case 66:
drawMode = BOTH;
break;
case 65:
showAll = !showAll;
break;
case 74:
if (tolerance > 0) tolerance -= 0.01;
findTemps();
break;
case 75:
tolerance += 0.01;
findTemps();
}
}
void mouseDragged() {
float yrot = (mouseY - pmouseY)/(zoom*zoom);
if (abs(yrot) < 50) {
speedY = yrot * 0.16 * -1;
}
boolean onOtherSide = abs((angleY -90) %360) > 180;
int f = onOtherSide? 1 : -1;
f *= (angleY -90) < 0? -1:1;
float xrot = (mouseX - pmouseX)/(zoom*zoom);
// println(angleX, angleY);
if (abs(xrot) < 50) {
speedX = xrot * 0.16 * f;
}
}
void mouseWheel(MouseEvent e){
wheelCount = e.getCount();
}
// Load temperature data from specific JSON file
void loadTemps(String file) {
JSONArray tmps = loadJSONArray(file);
temps = new TempPoint[tmps.size()];
for (int i = 0; i < tmps.size(); i++) {
JSONObject obj = tmps.getJSONObject(i);
float lat = obj.getFloat("lat");
float lon = obj.getFloat("lon");
float tmp = obj.getFloat("tmp");
float prs = obj.getFloat("prs");
int latIndex = round((lat + 90) * res);
TempPoint newPoint = new TempPoint(lon, lat, tmp, prs);
temps[i] = newPoint;
ArrayList<TempPoint> current = tempList.get(latIndex);
current.add(newPoint);
}
}
// Load the bulk data downloaded from the web
void loadTemps() {
JSONArray tmps = loadJSONArray("weather.json");
temps = new TempPoint[tmps.size()];
for (int i = 0; i <= tmps.size(); i++) {
JSONObject obj = tmps.getJSONObject(i);
//print(".");
float lat = obj.getJSONObject("city").getJSONObject("coord").getFloat("lat");
float lon = obj.getJSONObject("city").getJSONObject("coord").getFloat("lon");
float tmp = obj.getJSONObject("main").getFloat("temp") - 273.15;
temps[i] = new TempPoint(lon, lat, tmp, 1000);
}
}
// view, which points are at the opposite side of the earth (test)
void oppositeTest() {
int index = frameCount % temps.length;
TempPoint first = temps[index];
float firstX = map(first.lat, -90, 90, height, 0);
float firstY = map(first.lon, -180, 180, 0, width);
ellipse(firstY, firstX, 20, 20);
TempPoint last = temps[temps.length-index];
float lastX = map(last.lat, -90, 90, height, 0);
float lastY = map(last.lon, -180, 180, 0, width);
ellipse(lastY, lastX, 20, 20);
stroke(255, 100, 150);
line(firstY, firstX, lastY, lastX);
ellipse(width/2, height/2, 10, 10);
}
void findTemps() {
//println(temps.length);
int numSame = 0;
int numSimilar = 0;
for (int i = 0; i <= tempList.size()/2; i++) {
for (int j = 0; j < tempList.get(i).size(); j ++) {
TempPoint first = tempList.get(i).get(j);
int newLat = (90*res - i) + (90*res);
int lonPlusHalf = ((tempList.get(i).size()/2) + j)%tempList.get(i).size();
TempPoint last = tempList.get(newLat).get(lonPlusHalf);
first.state = TempPoint.DEF;
last.state = TempPoint.DEF;
if (abs(first.temperature - last.temperature) < tolerance) {
first.state = TempPoint.PRI;
last.state = TempPoint.PRI;
numSimilar++;
if (abs(first.airpressure - last.airpressure) < 0.1) {
first.state = TempPoint.BTH;
last.state = TempPoint.BTH;
numSame++;
}
//println(first.lon, "\t", last.lon, "\t", first.lon-last.lon, "\t", first.lat, "\t", last.lat, "\t", first.temperature, "\t", first.airpressure);
}
}
}
text(numSame + "/" + numSimilar + "@" + nf(tolerance, 1, 2).replace(",", "."), width-180, height-20);
}