# How do I move multiple objects in a circle in order

**URL:** <https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101>\
**Category:** Coding Questions\
**Created:** [December 4, 2019, 5:50am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101 "2019-12-04T05:50:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DudVudAura](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@DudVudAura](https://discourse.processing.org/u/DudVudAura)\
**Post date:** [December 4, 2019, 5:50am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101/1 "2019-12-04T05:50:51Z")

</div>

This is the code I have

```auto
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.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 4, 2019, 6:04am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101/2 "2019-12-04T06:04:02Z")

</div>

please format your code posting by pasting it into the

```auto
</> 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.

* * *

---

<div class="post-metadata">

**Author:** ![DudVudAura](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@DudVudAura](https://discourse.processing.org/u/DudVudAura)\
**Post date:** [December 4, 2019, 6:12am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101/3 "2019-12-04T06:12:07Z")

</div>

```auto
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);

}
 

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 4, 2019, 6:30am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101/4 "2019-12-04T06:30:31Z")

</div>

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:

```auto
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();
}

```

 ![rotating_circles](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0a748aaa988929819d3c93332ec0853cc346388f.png)

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

---

<div class="post-metadata">

**Author:** ![DudVudAura](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@DudVudAura](https://discourse.processing.org/u/DudVudAura)\
**Post date:** [December 4, 2019, 6:35am UTC](https://discourse.processing.org/t/how-do-i-move-multiple-objects-in-a-circle-in-order/16101/5 "2019-12-04T06:35:12Z")

</div>

Thanks this helps a lot!
