# Rotating rects around a circle perimeter pointing to the center

**URL:** https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868
**Category:** Beginners
**Created:** [April 2, 2019, 12:41pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868 "2019-04-02T12:41:39Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Michalis](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Michalis](https://discourse.processing.org/u/Michalis)
#### Post date: [April 2, 2019, 12:41pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/1 "2019-04-02T12:41:39Z")

</div>

Hello,  
I want to achieve something like _[this](http://printingcode.runemadsen.com/examples/form/sincos_rotation/)_ but I have no idea how. I checked almost every example, on the application and on the website, checked libraries, googled, but still, I didn’t manage to find a solution (sorry if I didn’t see something similar for processing already existing). I don’t know how to write this code written in p5.js for processing. Any help would be really appreciated. Thanks in advance! 😊

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [April 2, 2019, 1:02pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/2 "2019-04-02T13:02:17Z")

</div>

Sample code:

```auto
void setup(){
  size(400,400);
  rectMode(CENTER);
}

void draw(){
  background(0);
  noStroke();
  fill(0,200,0);
  translate(width/2, height/2);
  for( int i = 0; i < 20; i++){
    rect( 150, 0, 40, 10 );
    rotate( TWO_PI / 20.0 );
  }
}

```

---

<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: [April 2, 2019, 1:03pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/3 "2019-04-02T13:03:20Z")

</div>

so the example is in p5.js,  
but you want play

> processing IDE 3.5.3 JAVA mode?

and need a translation?

```auto
translate( width/2,height/2);
fill(200,0,0);
for ( int i =0; i<30; i++ ) {
  rotate(TWO_PI/30.0);
  rect ( 30,0,10,2);
}

```

![SNAG-0051](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8dfc2eb6b08ab95bd1a615d9919ee093cefe38d7.jpeg)

pls understand how rotation works in processing

- first move to center with translate
- rotate ( 0 ) starts right side
- rotate ( dalpha ) is clockwise.

---

<div class="post-metadata">

### Author: ![Michalis](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Michalis](https://discourse.processing.org/u/Michalis)
#### Post date: [April 2, 2019, 2:14pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/4 "2019-04-02T14:14:49Z")

</div>

Thanks for the replies so far. However I can’t rotate them without having them overlapping.

```auto
float x=TWO_PI/30;
void draw() {
  x+=.0001;
  background(0);
  translate(width/2, height/2);
  fill(200, 0, 0);
  for (int i =0; i<30; i++ ) {
    rotate(x);
    rect (30, 0, 10, 2);
  }
}

```

---

<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: [April 2, 2019, 2:35pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/5 "2019-04-02T14:35:06Z")

</div>

> [@Michalis](#):
>
> x+=.0001;

disable that line and try again

---

<div class="post-metadata">

### Author: ![Michalis](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Michalis](https://discourse.processing.org/u/Michalis)
#### Post date: [April 2, 2019, 2:57pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/6 "2019-04-02T14:57:05Z")

</div>

I mean, I can’t animate them to move around…

---

<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: [April 2, 2019, 3:00pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/7 "2019-04-02T15:00:30Z")

</div>

i go in a total other way,  
but ok, even can rotate this:

```auto
float many = 60;
float x=TWO_PI/many;
float ang = 0, dang= 0.01;

void setup() {
  size(200, 200); 
  noStroke();
  fill(200, 0, 0);
  textSize(10);
  rectMode(CENTER);
}

void draw() {
  background(200, 200, 0);
  translate(width/2, height/2);
  rotate(-PI/2.0+ang);
  ang += dang;   
  show_sec();
}

void show_sec() {
  for (int i =0; i<many; i++ ) {
    rect (75, 0, 10, 5);
    if ( i%5 == 0) { 
      text(i, 87, 5);
      strokeWeight(0.1);
      stroke(0);
      line(0, 0, 70, 0);
      noStroke();
    }
    rotate(x);
  }
}

```

---

<div class="post-metadata">

### Author: ![Michalis](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Michalis](https://discourse.processing.org/u/Michalis)
#### Post date: [April 2, 2019, 3:13pm UTC](https://discourse.processing.org/t/rotating-rects-around-a-circle-perimeter-pointing-to-the-center/9868/8 "2019-04-02T15:13:09Z")

</div>

Thank you! 🙂
