We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › CurVertex():similar tech as curvePoints() (tan)
Page Index Toggle Pages: 1
CurVertex():similar tech as curvePoints() (tan?) (Read 532 times)
CurVertex():similar tech as curvePoints() (tan?)
Jul 15th, 2008, 3:38pm
 
Basically, I can't find a way to use strokeWeight on curveVertex() as I want my curveVertex() to start with a high strokeWeight and end up with a low strokeWeight.

So, if I could evaluate the curveVertex at different points like with curvePoints, I could draw a lot of short lines with a decreasing strokeWeight.

UPDATE:
Look like there is something to do with tangente:
http://www.gamedev.net/reference/articles/article1497.asp

UPDATE 2:
By using tan I could draw a curveVertex parallel to the first one. Link them by the extremities. And fill the shape.
Any idea how to do this? (hehe)
Re:  CurVertex():similar tech as curvePoints(
Reply #1 - Jul 15th, 2008, 8:46pm
 
i've been wanting to do the same thing, i ended up using a triangle strip created around a curved point list, using atan to create width which i could decrease incrementally. i can post some code if you want.
Re:  CurVertex():similar tech as curvePoints(
Reply #2 - Jul 15th, 2008, 10:51pm
 
That would be great to see your code.
Here is what we came up with. I posted the code in this subject if you are interested:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1216033701
Re:  CurVertex():similar tech as curvePoints(
Reply #3 - Jul 16th, 2008, 10:42am
 
this is a bit if a crude extraction from the program im working on, sorry its a bit messy, but hopefully you'll get the idea.
i use a particle system to create a flowing list of points, then iterate through the list using below loop to create a tri strip, which has a triwidth var to control width.



Particle p = physics.makeParticle( 1.0, xvel, yvel, 0 );
int num=physics.numberOfParticles()-1;

 
   ptest=p;
   previous=last;

     //first 2 tangents
     float p1x1=previous.position().x();
     float p1y1=previous.position().y();
     float p1x2=last.position().x();
     float p1y2=last.position().y();  

     //second 2 tangents
     float p2x1=last.position().x();
     float p2y1=last.position().y();
     float p2x2=ptest.position().x();
     float p2y2=ptest.position().y();


//start your loop here

   beginShape(TRIANGLE_STRIP);


     Particle ptest = physics.getParticle( i );


     //*****************
     float p1x1,p1y1,p1x2,p1y2,p1x3,p1y3,p1x4,p1y4,p2x1,p2y1,p2x2,p2y2,p2x3,p2y3,p2x4,p2y4;

     float triwidth;
     float ang;

     //*****************

     //first 2 tangents
     p1x1=previous.position().x();
     p1y1=previous.position().y();
     p1x2=last.position().x();
     p1y2=last.position().y();  

     //second 2 tangents
     p2x1=last.position().x();
     p2y1=last.position().y();
     p2x2=ptest.position().x();
     p2y2=ptest.position().y();

 
     //width of snake/curve
       triwidth=5;

       //set actual x,y pos
       ang=atan2(p1y2-p1y1,p1x2-p1x1)-HALF_PI;
       p1x3=triwidth*cos(ang);
       p1y3=triwidth*sin(ang);

       p1x4=triwidth*cos(ang);
       p1y4=triwidth*sin(ang);

       ang=atan2(p2y2-p2y1,p2x2-p2x1)-HALF_PI;
       p2x3=triwidth*cos(ang);
       p2y3=triwidth*sin(ang);

       p2x4=triwidth*cos(ang);
       p2y4=triwidth*sin(ang);  

       //draw trianglestrip
       vertex(p1x3+p2x1,p1y3+p2y1,0);
       vertex(p1x4+p2x1,p1y4+p2y1,0);
       vertex(p2x3+p2x1,p2y3+p2y1,0);
       vertex(p2x4+p2x1,p2y4+p2y1,0);
     

     previous=last;
     last=ptest;

   endShape();

// end of loop
Re:  CurVertex():similar tech as curvePoints(
Reply #4 - Jul 16th, 2008, 10:50am
 
another way i was thinking, is to use curvePoint() to create a list of points and then draw eliipses along them at different sizes to create tapering ends and thickness, i'll prob try this myself as thats where im at with my current program.
Re:  CurVertex():similar tech as curvePoints(
Reply #5 - Jul 16th, 2008, 4:44pm
 
I couldn't make your code work. But does the fact that you use Triangle_strip make the 'snake' look smoother?

I don't know about the second solution... I tried something like that but didn't look as smooth as using vertex or curveVertex. And I was not sure about drawing more then twice as more dots than lines.

I am stuck with the curveVertex() technic. We've got the weight working but then doing a gradient fill() is a bit tricky as texture only works in 3D.

The problem is that it gets all jerky when moving slowly. The render can definitely be improve.

Quote:
static final int V_MAX = 20; // Max nb of vertices
static final float L_MAX = 500.0; // Max length

float[] X = new float[V_MAX];
float[] Y = new float[V_MAX];
float[] V = new float[V_MAX];
float[] W = new float[V_MAX];

float len;
int lastV;
float detail, weight = 20;

int type;

void setup() {
 size(500, 500);  
}

void draw() {
 smooth();
 background(255);
 fill(0);
 stroke(0);

 X[0] = mouseX;
 Y[0] = mouseY;

 if ( mouseX != pmouseX || mouseY != pmouseY){
   for (int i = V_MAX-1; i > 0; i--) {
     X[i] = X[i-1];  
     Y[i] = Y[i-1];
   }
   len = 0.0;
   lastV = 1;
   for (; lastV < V_MAX; lastV++) {
     float d = dist(X[lastV], Y[lastV], X[lastV - 1], Y[lastV - 1]);
     if (len + d > L_MAX)
       break;
     len += d;
   }
 }


 for (int i = 1; i < lastV-1; i++) {
   println(i);
   if (i==2){
     weight = 0;
   }
   else{
     weight = map(i, 2, lastV-3, 20, 0);
   }
   V[i] = thicknessX(X[i-1], X[i], X[i+1], Y[i-1], Y[i], Y[i+1], weight);
   W[i] = thicknessW(X[i-1], X[i], X[i+1], Y[i-1], Y[i], Y[i+1], weight);

 }
 // println(W);
 noFill();
 curveTightness(0);
 beginShape();
 for (int i = 1; i < lastV-1; i++) {
   strokeWeight(1);
   curveVertex(X[i], Y[i]);
 }
 endShape();

 beginShape();
 for (int i = 1; i < lastV-1; i++) {
   strokeWeight(1);
   curveVertex(V[i], W[i]);
 }
 endShape();

}
/*The parrallel line fuctions*/

float thicknessX(float Xa, float Xb, float Xc, float Ya, float Yb, float Yc, float h){
 float T = atan2(Ya-Yc, Xa-Xc);
 float V = Xb+h*cos(T+HALF_PI);
 return V;
}
float thicknessW(float Xa, float Xb, float Xc, float Ya, float Yb, float Yc, float h){
 float T = atan2(Ya-Yc, Xa-Xc);
 float W = Yb+h*sin(T+HALF_PI);
 return W;

}
Re:  CurVertex():similar tech as curvePoints(
Reply #6 - Jul 16th, 2008, 8:22pm
 
the code wont work unless you put it in your own loop to test through a particle list, it was just a rough posting of some code to show the theory.... sorry i cant be of more help. the tri strip is very smooth and very fast though.
Re:  CurVertex():similar tech as curvePoints(
Reply #7 - Jul 17th, 2008, 11:29am
 
ok, thanks for the tip. I've put it in loop and all that but could'nt get the particules to works. Never mind I have another go at it later.

Thanks
Page Index Toggle Pages: 1