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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
import geomerative.*;
//drawing commands and utils for vodaviz
float log10 (float x) {
return (log(x) / log(10));
}
class pointNormalise {
//take pixel coords and turn into lat/lng radians
float xo,xs,yo,ys;
pointNormalise(float _xo,float _xs,float _yo,float _ys) {
xo=_xo;
xs=_xs;
yo=_yo;
ys=_ys;
}
RPoint alise(RPoint p) {
//normalise
float px=(((p.x-xo)/xs)-0.5)*PI*2; //26)/736);
float py=(((p.y-yo)/ys)-0.5)*PI; //90)/390);
return new RPoint(px,py);
}
}
class pointTransform {
RPoint form(RPoint in) {
//transform
return new RPoint (((in.x*0.053)+(PI/2)-.01),((in.y)*0.14)+(PI/2)-.1); //front half of sphere
}
}
class sphereMap {
RPoint per(RPoint p,float _r) {
//map to 3D sphere
float r=getHeight()*_r;
float x=r*cos(p.x)*(sin(p.y)) *4;
float z=r*sin(p.x)*(sin(p.y)) -985;
float y=r*cos(p.y)+(getHeight()*1)-330;
//camera at 0,0,0
//screen plane at 0,0,100
//(dx-ex)(ez/dz)
//(dy-ey)(ez/dz)
//rotate camera
//transform into 2D plane @100
return new RPoint(x*(100/z),y*(100/z));
}
}
RPoint screenMapper(RPoint p) {
p.x=((p.x*getWidth())/(PI*2))+(getWidth()/2);
p.y=((p.y*getHeight())/PI)+(getHeight()/2);
return p;
}
RPoint plerp(RPoint s,RPoint e,float a) {
return new RPoint(lerp(s.x,e.x,a),lerp(s.y,e.y,a));
}
float GSphereDist(RPoint p1,RPoint p2) {
return acos(sin(p1.y)*sin(p2.y)+cos(p1.y)*cos(p2.y)*cos(p1.x-p2.x));
}
RPoint GCircFract(RPoint sp,RPoint ep,float f) {
//interpolates two lat-lng points on a great circle
float d=GSphereDist(sp,ep);
float A=sin((1-f)*d)/sin(d);
float B=sin(f*d)/sin(d);
float x = A*cos(sp.y)*cos(sp.x) + B*cos(ep.y)*cos(ep.x);
float y = A*cos(sp.y)*sin(sp.x) + B*cos(ep.y)*sin(ep.x);
float z = A*sin(sp.y) + B*sin(ep.y);
return new RPoint(atan2(y,x),atan2(z,sqrt(pow(x,2)+pow(y,2))));
}
void ellipse3d(RPoint pos,float s,float r){
//take ellipse coord in UV space
//return in 3d globe space
float er=s*0.5;
curveTightness(-0.67);
RPoint s1=smap.per(new RPoint(pos.x-er,pos.y),r);
RPoint s2=smap.per(new RPoint(pos.x,pos.y-er),r);
RPoint s3=smap.per(new RPoint(pos.x+er,pos.y),r);
RPoint s4=smap.per(new RPoint(pos.x,pos.y+er),r);
beginShape();
curveVertex(s1.x+hw, s1.y+hh);
curveVertex(s2.x+hw, s2.y+hh);
curveVertex(s3.x+hw, s3.y+hh);
curveVertex(s4.x+hw, s4.y+hh);
curveVertex(s1.x+hw, s1.y+hh);
curveVertex(s2.x+hw, s2.y+hh);
curveVertex(s3.x+hw, s3.y+hh);
endShape();
}
class bezierstroke {
float startsize,endsize,linewidth,mpfract,raisefract,bezierfract;
bezierstroke(float _s,float _e,float _l,float _m,float _r,float _b){
startsize=_s;
endsize=_e;
linewidth=_l;
mpfract=_m;
raisefract=_r;
bezierfract=_b;
}
void drawstroke(RPoint start,RPoint end) {
ellipse(start.x,start.y,startsize,startsize);
ellipse(end.x,end.y,endsize,endsize);
RPoint mp=new RPoint(start.x+((end.x-start.x)*mpfract),(start.y+((end.y-start.y)*mpfract))-((getHeight()-(start.y+((end.y-start.y)*mpfract)))*raisefract));
RPoint bv=new RPoint((end.x-start.x)*bezierfract,(end.y-start.y)*bezierfract);
RPoint b1=new RPoint(mp.x-bv.x,mp.y-bv.y);
RPoint b2=new RPoint(mp.x+bv.x,mp.y+bv.y);
beginShape();
vertex(start.x,start.y);
bezierVertex(start.x,start.y,b1.x,b1.y-(linewidth/2),mp.x,mp.y-(linewidth/2));
bezierVertex(b2.x,b2.y-(linewidth/2),end.x,end.y,end.x,end.y);
bezierVertex(end.x,end.y,b2.x,b2.y+(linewidth/2),mp.x,mp.y+(linewidth/2));
bezierVertex(b1.x,b1.y+(linewidth/2),start.x,start.y,start.x,start.y);
endShape();
}
}
RPoint perpoint(RPoint p1,RPoint p2,float d) {
//returns a point left distance d of perpendicular line between points
float h=atan2(p2.y-p1.y,p2.x-p1.x);
return new RPoint(p2.x+(cos(h+HALF_PI)*d),p2.y+(sin(h+HALF_PI)*d));
}
class gradientstroke {
float startsize,endsize,mpfract,raisefract,bezierfract;
float[] transpos;
float[] transamt;
color col;
gradientstroke(float _s,float _e,float[] _p, float[] _a,color _c){
startsize=_s;
endsize=_e;
transpos=_p;
transamt=_a;
col=_c;
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noStroke();
fill(red(_col),green(_col),blue(_col),255);
//put ellipses in a seperate layer
//ellipse(Sp.x,Sp.y,startsize,startsize);
//ellipse(Ep.x,Ep.y,endsize,endsize);
//construct quads along path
//path is straight, curve comes from 3D/ raise
//how to deal with badly formatted control arrays? bother?
//3d stage in between
noFill();
float spos=0.0;
float step=.004; //optimise
//quad corner points
//these are perpedicular on the screen as we are making a gradient line system
RPoint L0,L1,p0,p1,p2,p3;
p0=new RPoint(0,0);
p1=p0;
L0=Sp;
boolean notfirst=false;
for (int i=0;i<transpos.length-1;i++) {
float transeg=transpos[i+1]-transpos[i];
for (float u=0;u<transeg-step;u+=step) {
float gradamt=u/transeg;
float b=255.0*((transamt[i]*(1-gradamt))+(transamt[i+1]*gradamt));
//find new point on line
L1=new RPoint(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u));
float lw=lerp(startsize,endsize,transpos[i]+u)/2;
p2=perpoint(L0,L1,lw);
p3=perpoint(L0,L1,-lw);
if (notfirst) {
fill(red(_col),green(_col),blue(_col),b);
beginShape();
vertex(p0.x,p0.y);
vertex(p2.x,p2.y);
vertex(p3.x,p3.y);
vertex(p1.x,p1.y);
endShape();
}
notfirst=true;
p0=p2;
p1=p3;
L0=L1;
/*
//temporarily draw line in 2D
strokeWeight(((1-(transpos[i]+u))*startsize)+((transpos[i]+u)*endsize));
stroke(red(col),green(col),blue(col),b);
line(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u),;
*/
}
}
}
}
class line3D {
float linewidth;
color col;
sphereMap smap;
float hw,hh;
line3D(float _l,color _c,sphereMap _sp){
linewidth=_l;
col=_c;
smap=_sp;
hw=(getWidth()/2);
hh=(getHeight()/2);
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noFill();
stroke(red(_col),green(_col),blue(_col),255);
strokeWeight(linewidth);
RPoint L0=smap.per(Sp,4);
RPoint L1=smap.per(Ep,4);
line(L0.x+hw,L0.y+hh,L1.x+hw,L1.y+hh);
}
}
class gradientstroke3D extends line3D {
float startsize,endsize,mpfract,raisefract,bezierfract;
float[] transpos;
float[] transamt;
gradientstroke3D(float _s,float _e,float[] _p, float[] _a,color _c,sphereMap _sp){
super(1.0,_c,_sp);
startsize=_s;
endsize=_e;
transpos=_p;
transamt=_a;
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noStroke();
fill(red(_col),green(_col),blue(_col),255);
//put ellipses in a seperate layer
//ellipse(Sp.x,Sp.y,startsize,startsize);
//ellipse(Ep.x,Ep.y,endsize,endsize);
//construct quads along path
//path is straight, curve comes from 3D/ raise
//how to deal with badly formatted control arrays? bother?
//3d stage in between
noFill();
float spos=0.0;
float step=0.03; //optimise
//quad corner points
//these are perpedicular on the screen as we are making a gradient line system
RPoint L0,L1,p0,p1,p2,p3;
p0=new RPoint(0,0);
p1=p0;
L0=Sp;
int iteration=0;
for (int i=0;i<transpos.length-1;i++) {
float transeg=transpos[i+1]-transpos[i];
for (float u=0;u<transeg-step;u+=step) {
float gradamt=u/transeg;
float b=255.0*((transamt[i]*(1-gradamt))+(transamt[i+1]*gradamt));
//find new point on line
L1=smap.per(new RPoint(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u)),4+(sin((transpos[i]+u)*PI)*0.1));
float lw=lerp(startsize,endsize,transpos[i]+u)/2;
p2=perpoint(L0,L1,lw);
p3=perpoint(L0,L1,-lw);
if (iteration>1) {
fill(red(_col),green(_col),blue(_col),b);
beginShape();
vertex(p0.x+hw,p0.y+hh);
vertex(p2.x+hw,p2.y+hh);
vertex(p3.x+hw,p3.y+hh);
vertex(p1.x+hw,p1.y+hh);
endShape();
}
iteration++;
p0=p2;
p1=p3;
L0=L1;
/*
//temporarily draw line in 2D
strokeWeight(((1-(transpos[i]+u))*startsize)+((transpos[i]+u)*endsize));
stroke(red(col),green(col),blue(col),b);
line(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u),;
*/
}
}
}
}
class greatcirclestroke3D extends line3D {
//draws a stroke with variable transparency that follows the great circle between two latlng
//doesn't look right
float[] transpos;
float[] transamt;
greatcirclestroke3D(float _l,float[] _p, float[] _a,color _c,sphereMap _sp){
super(_l,_c,_sp);
transpos=_p;
transamt=_a;
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
}
void drawstroke(RPoint Sp,RPoint Ep,color _col) {
noFill();
strokeWeight(linewidth);
float spos=0.0;
float step=0.01; //optimise
RPoint L0,L1;
L0=Sp;
int iteration=0;
for (int i=0;i<transpos.length-1;i++) {
float transeg=transpos[i+1]-transpos[i];
for (float u=0;u<transeg-step;u+=step) {
float gradamt=u/transeg;
float b=255.0*((transamt[i]*(1-gradamt))+(transamt[i+1]*gradamt));
//find new point on line
L1=smap.per(GCircFract(Sp,Ep,transpos[i]+u),4); //+(sin((transpos[i]+u)*PI)*0.1));
//L1=smap.per(new RPoint(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u)),4+(sin((transpos[i]+u)*PI)*0.1));
//float lw=lerp(startsize,endsize,transpos[i]+u)/2;
if (iteration>1) {
stroke(red(_col),green(_col),blue(_col),b);
line(L0.x+hw,L0.y+hh,L1.x+hw,L1.y+hh);
}
iteration++;
L0=L1;
/*
//temporarily draw line in 2D
strokeWeight(((1-(transpos[i]+u))*startsize)+((transpos[i]+u)*endsize));
stroke(red(col),green(col),blue(col),b);
line(lerp(Sp.x,Ep.x,transpos[i]+u),lerp(Sp.y,Ep.y,transpos[i]+u),;
*/
}
}
}
}
|