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 › Move an object along spline (circle) ?
Page Index Toggle Pages: 1
Move an object along spline (circle) ?? (Read 1916 times)
Move an object along spline (circle) ??
Jan 20th, 2010, 7:21am
 
How can I move an object along a path, a spline...

I want to move a ligne of text along a circle...
I could calculate an Array of pixels that defines the circle, and move the object than along.

But is there an easier method?
Could the Animation-libraries help?
Re: Move an object along spline (circle) ??
Reply #1 - Jan 20th, 2010, 7:37am
 
Circles are easy - just use trigonometry.  Curves are perhaps a little more complex.  For an example see moving on curves.
Re: Move an object along spline (circle) ??
Reply #2 - Jan 20th, 2010, 7:40am
 
Here's how I would move text along a circle:

Code:

int cx = 250;
int cy = 250;
int r = 100;

void setup()
{
size(500, 500);
textFont(createFont("Arial", 30));
}

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

float t = millis()/1000.0f;
int x = (int)(cx+r*cos(t));
int y = (int)(cy+r*sin(t));

text("Test", x, y);
}
Re: Move an object along spline (circle) ??
Reply #3 - Jan 20th, 2010, 8:11am
 
if you dont want to calculate it, and want to move along some more complex path you can either use http://processing.org/reference/bezierPoint_.html or use geomerative to get on array of points of the outline of a shape.
Re: Move an object along spline (circle) ??
Reply #4 - Jan 20th, 2010, 8:18am
 
You might also find textAlign() useful.  As in:

Code:
  textAlign(CENTER, CENTER);
 text("Test", x, y);

Re: Move an object along spline (circle) ??
Reply #5 - Jan 20th, 2010, 12:33pm
 
JR, this code for moving on a circle works very fine. Thank you!
But how can I now rotate the text "in the direction of travel" ??
Re: Move an object along spline (circle) ??
Reply #6 - Jan 20th, 2010, 1:19pm
 
rotate it by t
Re: Move an object along spline (circle) ??
Reply #7 - Jan 20th, 2010, 2:54pm
 
Cedric wrote on Jan 20th, 2010, 1:19pm:
rotate it by t

Cool

For completeness:

Code:

int cx = 250;
int cy = 250;
int r = 100;

void setup()
{
 size(500, 500);
 textFont(createFont("Arial", 30));
 
}

void draw()
{
 background(0);
 stroke(255);
 
 float t = millis()/1000.0f;
 int x = (int)(cx+r*cos(t));
 int y = (int)(cy+r*sin(t));
 
 pushMatrix();
 translate(x, y);
 rotate(t);//or rotate(t-PI/2); (depending on what you need)
 textAlign(CENTER, CENTER);
 text("Test", 0, 0);
 popMatrix();
}
Re: Move an object along spline (circle) ??
Reply #8 - Jan 20th, 2010, 3:27pm
 
i was a bit lazy,i know Smiley
Re: Move an object along spline (circle) ??
Reply #9 - Jan 21st, 2010, 8:34am
 
YESSSS! Merci! Cheesy
Re: Move an object along spline (circle) ??
Reply #10 - Jan 21st, 2010, 9:18am
 
Pas de problème Wink
Page Index Toggle Pages: 1