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);
}
}