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.
Page Index Toggle Pages: 1
Circular Motion (Read 652 times)
Circular Motion
Jul 12th, 2009, 4:14pm
 
Hi,

I'm trying to find the best way to make an object move circularly around the perimeter of another object. What is the best way to do so. (i.e. an ellipse around another ellipse both of which are objects). Thanks. I appreciate any suggestions.

Here is what I'm working on. I havn't made the bigger circle a class yet.

Code:
int num = 500;
Circle [] circles=new Circle[num];
void setup(){
smooth();
size(400, 400);
frameRate(30);
for (int i = 0; i<num; i++){
circles[i] = new Circle(random(1,25), 25);
}

}

void draw(){
noStroke();
fill(204, 75);
rect(0, 0, height, width);
stroke(0);
ellipse(width/2, height/2, width-10, height-10);

stroke(0);
fill(10, 25);
for (int i = 0; i<num; i++){
circles[i].update();
}
}

class Circle{
float speed, diameter;
float xpos = width/2;
float ypos = height/2;
float r = random(1, 255);
float g = random(1, 255);
float b = random(1, 255);
float a = random(1, 100);

Circle(float s, float d){
speed = s;
diameter = d;
}

void update(){
xpos += speed*(random(0-1));
ypos += speed*(random(0-1));
if( xpos < 0 || xpos > width || ypos < 0 || ypos > height){
speed *= -1;
}

fill(r,g,b,a);
ellipse(xpos, ypos, diameter, diameter);
}
}
Re: Circular Motion
Reply #1 - Jul 12th, 2009, 5:07pm
 
you have to polarize your coords...

add to class:
 float angulo = random(PI*2/2*2);
 float raio = 0;


use this for update:
   angulo+=radians(speed);
   raio = raio + ( 200 - raio)*0.025;          
   xpos = cos(angulo)*raio + width/2;
   ypos = sin(angulo)*raio + height/2;
   
   fill(r,g,b,a);
   ellipse(xpos, ypos, diameter, diameter);

hth
Re: Circular Motion
Reply #2 - Jul 14th, 2009, 11:47am
 
Thanks! That's a great start. I appreciate the help.
Page Index Toggle Pages: 1