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 › grow a line from point a to b
Page Index Toggle Pages: 1
grow a line from point a to b (Read 593 times)
grow a line from point a to b
Dec 5th, 2009, 2:14pm
 
hi,

i'm trying to figure out the easiest way to have a line grow from one point to another (assuming both points are known in advance). so for :

Code:
line(x1,y1,x2,y2); 



x1, y1 would grow and connect to x2, y2 over the span of a second. i've considered using images to mask the lines, but i'm not sure what the code would look like to do that and  also plan on using a great number of lines (might not be the most efficient method).  i also would like to do this with curved lines as well. anyone know the best way to accomplish this?

thanks!
Re: grow a line from point a to b
Reply #1 - Dec 6th, 2009, 12:12am
 
Interpolation

Code:

int x1 = 10;
int y1 = 10;

int x2 = 100;
int y2 = 20;

float interpolate = 0;

int startTime;
int growTime = 1000;//1s

void setup()
{
size(200, 200);
int startTime = millis();
}

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

interpolate = (float)(millis()-startTime)/growTime;
if(interpolate < 1)
{
line(x1, y1,
(int)( (1-interpolate)*x1 + interpolate*x2 ),
(int)( (1-interpolate)*y1 + interpolate*y2 ) );
}
else
{
startTime = millis();
}
}
Page Index Toggle Pages: 1