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 & HelpPrograms › Elasticity - Lines
Page Index Toggle Pages: 1
Elasticity - Lines (Read 414 times)
Elasticity - Lines
Apr 8th, 2010, 6:52pm
 
Hi,
I'm trying to achieve an elastic motion by using berzierVertex, what I want to achieve is the same look as a rubber band attached to my mouse coordinates, so I started with this example:

Code:

float inertia = 0.9;
float k = 0.1; //spring
float xp; //acceleration


void draw(){
 //
 fill(0);
 rect(0,0,width, height);
 //
 stroke(150);
 noFill();
 beginShape();
 //
 float xstart = 40;
 float ystart = 20;
 float c = dist(mouseX, mouseY, xstart, ystart);
 vertex(xstart, ystart);
 xp = xp *inertia + c*k;
 c += xp;
 bezierVertex(c,c,c,c,mouseX, mouseY);
 endShape();
}



How could I implement the elastic effect on my var "c" in this case.

Re: Elasticity - Lines
Reply #1 - Apr 8th, 2010, 10:17pm
 
I got a result that I'm pretty happy with, so I'll share it here:
Code:

float inertia = 0.9;
float k = 0.1; //spring
float xp; //acceleration
float m = 0.1;
float x;
float easing = 0.05;

void draw(){
smooth();
//
fill(100);
rect(0,0,width, height);
//
stroke(150);
noFill();
beginShape();
//
float xstart = 40;
float ystart = 20;
//
float targetX = mouseX;
float dx = targetX - x;
if(abs(dx) > 1) {
x += dx * easing;
}

vertex(xstart, ystart);
bezierVertex(x,x,x,x,mouseX, mouseY);
endShape();
}




Page Index Toggle Pages: 1