Trying to make star spin with mouse interaction

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.

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

I advise you check out the following doc:

Below is a quick exemple using a simple rectangle.

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();
}
4 Likes

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

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