How do I move multiple objects in a circle in order

This is the code I have

int cx = 250;
int cy = 250;
int r = 100;
int cq = 250;
int ce = 250;
int d = 150;

void setup()
{
  size(500, 500);
}

void draw()
{
  background(0);
noStroke();
  fill(random(0,255),random(0,255),random(0,255));
  float t = millis()/150.0f;
  int x = (int)(cx+r*cos(t));
  int y = (int)(cy+r*sin(t));

ellipse(x,y,50,50);
  float i = millis()/-250.0f;
  int q = (int)(cq+d*cos(i));
  int e = (int)(ce+d*sin(i));
ellipse(q,e,50,50);
}

Right now I just have 2 ellipses that go in circles in opposite directions but I want to add more circles that follow behind the other circles.

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


int cx = 250;
int cy = 250;
int r = 100;
int cq = 250;
int ce = 250;
int d = 150;
int cu = 250;
int cp = 250;
int o = 200;

void setup()
{
  size(500, 500);
}

void draw()
{
  background(0);
noStroke();
fill(255);
ellipse(250,250,50,50);
fill(0);
ellipse(250,250,40,40);
fill(255);
ellipse(250,250,30,30);
fill(0);
ellipse(250,250,20,20);

  float t = millis()/150.0f;
  int x = (int)(cx+r*cos(t));
  int y = (int)(cy+r*sin(t));
fill(255);
ellipse(x,y,50,50);
fill(0);
ellipse(x,y,45,45);
fill(255);
ellipse(x,y,40,40);
fill(0);
ellipse(x,y,35,35);
fill(255);
ellipse(x,y,30,30);
fill(0);
ellipse(x,y,25,25);
  float i = millis()/-140.0f;
  int q = (int)(cq+d*cos(i));
  int e = (int)(ce+d*sin(i));
fill(255);
ellipse(q,e,50,50);
fill(0);
ellipse(q,e,45,45);
fill(255);
ellipse(q,e,40,40);
fill(0);
ellipse(q,e,35,35);
fill(255);
ellipse(q,e,30,30);
fill(0);
ellipse(q,e,25,25);

float l = millis()/130.0f;
  int u = (int)(cu+o*cos(l));
  int p = (int)(cp+o*sin(l));
fill(255);
ellipse(u,p,50,50);
fill(0);
ellipse(u,p,45,45);
fill(255);
ellipse(u,p,40,40);
fill(0);
ellipse(u,p,35,35);
fill(255);
ellipse(u,p,30,30);
fill(0);
ellipse(u,p,25,25);

}
 

thanks, but i want ask you to repair the first post too.

now there are other ways,
one is to use

FOR loops to repeat some action,

other is instead of your good circle X/Y position calculation

could use ROTATE.

example:

int many = 5;
float ang=0,dang=-0.01;

void setup() {
  size(500, 500);
  fill(0, 0, 200);
  stroke(0, 200, 0);
  strokeWeight(5);
}

void draw() {
  background(200, 200, 0);
  translate(width/2, height/2);
  circle(0, 0, 100);
  circle(0, 0, 50);
  rotate(ang);
  ang+=dang;
  push();
  for (int i= 0; i < many; i++) {
    rotate(TAU/10);
    circle(150, 0, 50-i*5);
  }
  pop();
}

is that the idea you had about the following smaller circles… or i misunderstand?

2 Likes

Thanks this helps a lot!

1 Like