summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bezierstroke.pde198
-rw-r--r--vodaviz.pde103
2 files changed, 177 insertions, 124 deletions
diff --git a/bezierstroke.pde b/bezierstroke.pde
index d7fc939..406e1c4 100644
--- a/bezierstroke.pde
+++ b/bezierstroke.pde
@@ -1,5 +1,105 @@
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){
@@ -110,22 +210,43 @@ class gradientstroke {
}
-class gradientstroke3D {
- float startsize,endsize,mpfract,raisefract,bezierfract;
- float[] transpos;
- float[] transamt;
+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;
- col=_c;
- smap=_sp;
- hw=(getWidth()/2);
- hh=(getHeight()/2);
+
}
void drawstroke(RPoint Sp,RPoint Ep) {
drawstroke(Sp,Ep,col);
@@ -190,33 +311,60 @@ class gradientstroke3D {
}
}
}
-
}
-class linear3D {
- float linewidth;
- color col;
- sphereMap smap;
- float hw,hh;
- linear3D(float _l,color _c,sphereMap _sp){
- linewidth=_l;
- col=_c;
- smap=_sp;
- hw=(getWidth()/2);
- hh=(getHeight()/2);
+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();
- 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);
+ 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),;
+ */
+
+
+ }
+ }
}
-
}
+
diff --git a/vodaviz.pde b/vodaviz.pde
index 89d82d1..368d2c8 100644
--- a/vodaviz.pde
+++ b/vodaviz.pde
@@ -94,102 +94,7 @@ cache points!
import processing.pdf.*;
import geomerative.*;
-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) {
- 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();
-}
RShape shp;
pointNormalise pnorm;
@@ -203,7 +108,7 @@ calldata calls;
bitmapcountry Ireland;
bezierstroke bstroke;
-linear3D gstroke;
+greatcirclestroke3D gstroke;
float hw,hh;
@@ -214,7 +119,7 @@ void setup(){
println("vodaviz v0.6");
RG.init(this);
- mode="PDF";
+ //mode="PDF";
if (mode=="PDF") size(832,220,PDF, "vodaviz_lines_220212.pdf"); //P3D); //832,220); //nb pdf is 800x600
else size(832,220); //,PDF, "testoutput.pdf"); //P3D); //832,220); //nb pdf is 800x600
@@ -249,7 +154,7 @@ void setup(){
float[] transpos={0.0,0.25,0.75,1.0};
float[] transamt={1.0,1.0,1.0,1.0}; //{0.5,0.05,0.05,0.5};
color col=color(0,0,0);
- gstroke=new linear3D(startsize,col,smap);
+ gstroke=new greatcirclestroke3D(startsize,transpos,transamt,col,smap);
RG.ignoreStyles();
println("loaded svg in "+((millis()-m)*.001)+" seconds");
@@ -370,7 +275,7 @@ void draw() {
if (true) { //draw gradient 3D lines
if (calls.countries.get(i).points.size()>0) {
- for (int j=0;j<log10(calls.countries.get(i).calls)*15;j++) {
+ for (int j=0;j<log10(calls.countries.get(i).calls)*1;j++) { //was *15
weightedpixel px=calls.countries.get(i).getpixel();
RPoint Sp=ptrans.form(pnorm.alise(px.randompt(5.0)));
RPoint Ep=ptrans.form(pnorm.alise(Ireland.getpoint()));