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 › Rotation Along A Path
Page Index Toggle Pages: 1
Rotation Along A Path (Read 914 times)
Rotation Along A Path
Jan 27th, 2010, 3:45pm
 
I am attempting to create a simple game in Java using Processing which utilizes paths and rotation in order to create an element of the game.  In this game, lines will appear at random, on click, at different positions along a circular path. You, the player, will control a circle with your mouse positioning and click in hopes of avoiding the randomly generated lines.

The only problem is that I do not know how to attach shapes to a path (specifically an elliptical path) in random order.  All of the shapes (lines, in this case) will extend through the screen.

Which functions should/can I use to create this effect?
Re: Rotation Along A Path
Reply #1 - Jan 27th, 2010, 5:35pm
 
Perhaps BezierCurve() and BezierPoint().
Re: Rotation Along A Path
Reply #2 - Jan 27th, 2010, 11:57pm
 
What specifically is it you have problems with? Finding the position where to create your objects?
Re: Rotation Along A Path
Reply #3 - Jan 28th, 2010, 11:51pm
 
knutEinar wrote on Jan 27th, 2010, 11:57pm:
What specifically is it you have problems with Finding the position where to create your objects



I am hoping to create them randomly around a circular path, encompassing the "play" area.
Re: Rotation Along A Path
Reply #4 - Jan 31st, 2010, 4:09am
 
To position something on a circular path, you can use the sin and cos function. Just assign a random number between 0 and TWO_PI (doesn't matter if it is out of this range either, but just to keep it simple) and use that value to define the point on the path.

Example: Code:
void setup(){
 size(500,500,P3D);
 frameRate(2);
}
void draw(){
translate(width/2, height/2); // place the circle in the middle of the canvas
float randomNum = random(TWO_PI);
float xpos = cos(randomNum)*200; // 200 is the radius of the circle
float ypos = sin(randomNum)*200;
translate(xpos,ypos);  // move to the point on the circle
box(10); // draw something at that point ...
}

The code is just an example, but I think it should work, although untested. Is this what you were looking for?
Edited:
It is now tested, and should work ...

Page Index Toggle Pages: 1