summaryrefslogtreecommitdiff
path: root/bezierstroke.pde
diff options
context:
space:
mode:
Diffstat (limited to 'bezierstroke.pde')
-rw-r--r--bezierstroke.pde166
1 files changed, 166 insertions, 0 deletions
diff --git a/bezierstroke.pde b/bezierstroke.pde
index 2cb85de..5070f9b 100644
--- a/bezierstroke.pde
+++ b/bezierstroke.pde
@@ -26,3 +26,169 @@ class bezierstroke {
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=.001; //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 gradientstroke3D {
+ float startsize,endsize,mpfract,raisefract,bezierfract;
+ float[] transpos;
+ float[] transamt;
+ color col;
+ sphereMap smap;
+ float hw,hh;
+ gradientstroke3D(float _s,float _e,float[] _p, float[] _a,color _c,sphereMap _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);
+ }
+ 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=.001; //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=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 (notfirst) {
+ 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();
+ }
+ 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),;
+ */
+
+
+ }
+ }
+ }
+
+}