# Trying to make star spin with mouse interaction

**URL:** https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302
**Category:** Coding Questions
**Tags:** homework
**Created:** [October 16, 2022, 5:24pm UTC](https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302 "2022-10-16T17:24:01Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)
#### Post date: [October 16, 2022, 5:24pm UTC](https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302/1 "2022-10-16T17:24:01Z")

</div>

Hi, so I got some help earlier on how to place rectangles across the plane in random spots. Now my next question is how i can make the star spin, have the rectangles pop up, and then stop after pressing the mouse again.

```auto
void setup(){
  size(1360, 1400);
}

void draw() {
  fill(41,171,226);
  stroke(255);
  strokeWeight(2);
  beginShape();
  vertex(785, 233);
  vertex(881,431);
  vertex(1098,464);
  vertex(939, 617);
  vertex(975, 834);
  vertex(781, 730);
  vertex(586, 831);
  vertex(625, 614);
  vertex(468, 460);
  vertex(686, 430);
  endShape(CLOSE);
}
  float r = 0;
  float g = 0;
  float b = 0;
  float a = 0;
  float X = 0;
  float Y = 0;

void mousePressed() {
  r = int(random(0, 255));
  g = int(random(0, 255));
  b = int(random(0, 255));
  a = int(random(0, 255));
  X = int(random(10, 60));
  Y = int(random(10, 60));
  fill(r, g, b, a);
  rectMode(CENTER);
  rect(mouseX, mouseY, X, Y);
}

```

---

<div class="post-metadata">

### Author: ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)
#### Post date: [October 16, 2022, 5:37pm UTC](https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302/2 "2022-10-16T17:37:39Z")

</div>

I advise you check out the following doc:

- [popMatrix()](https://processing.org/reference/popMatrix_.html)
- [pushMatrix](https://processing.org/reference/pushMatrix_.html)
- [translate()](https://processing.org/reference/translate_.html)
- [rotate()](https://processing.org/reference/rotate_.html)

Below is a quick exemple using a simple rectangle.

```auto
float angle = 0;
float rectCenterX = 300;
float rectCenterY = 300;

void setup() {
  size(600, 600);
  background(20);
}

void draw() {
  background(20);
  
  drawMyStar();
  
  angle += 0.01;
}

void drawMyStar() {
  noStroke();
  fill(240);
  rectMode(CENTER);
  
  pushMatrix();
  translate(rectCenterX, rectCenterY);
  rotate(angle);
  translate(-rectCenterX, -rectCenterY);
  rect(rectCenterX, rectCenterY, 100, 100);
  popMatrix();
}

```

---

<div class="post-metadata">

### Author: ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)
#### Post date: [October 16, 2022, 5:45pm UTC](https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302/3 "2022-10-16T17:45:37Z")

</div>

Would i be able to take this remove the void setup size and change the rectMode to i guess a star mode?

---

<div class="post-metadata">

### Author: ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)
#### Post date: [October 17, 2022, 8:13am UTC](https://discourse.processing.org/t/trying-to-make-star-spin-with-mouse-interaction/39302/4 "2022-10-17T08:13:50Z")

</div>

Hello @JHProcess I’ve edited your post to format the code. For future posts, please use the code formatting button 🙏 Thanks!

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/4/a/4a13843953aca71003a6c52141c228cb44ebae25.png)
