# How to randomize colors

**URL:** https://discourse.processing.org/t/how-to-randomize-colors/16136
**Category:** Coding Questions
**Created:** [December 5, 2019, 1:34am UTC](https://discourse.processing.org/t/how-to-randomize-colors/16136 "2019-12-05T01:34:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![masterU](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@masterU](https://discourse.processing.org/u/masterU)
#### Post date: [December 5, 2019, 1:34am UTC](https://discourse.processing.org/t/how-to-randomize-colors/16136/1 "2019-12-05T01:34:03Z")

</div>

Hello all, I am doing a recreation of Pink Floyd’s famous album with a twist - I want every time the mouse is pressed, the colors on the spectrum random and change. This is what I have so far:

```auto
PImage img;
PFont helvetica;
PFont helveticaBold;

String band = "PINK FLOYD";
String title = "DARK SIDE OF THE MOON";
color randomC = color(random(1,360),random(1,360),random(1,360));

void setup() {
size (600,600);
img = loadImage ("data/bg.jpg");
helvetica = loadFont ("data/Helvetica-48.vlw");
helveticaBold = loadFont ("data/Helvetica-Bold-48.vlw");
smooth();
}

void draw() {
  
  album();

}
void album() {
//Background image
  image(img, 0, 0);
  
//Album name and band
  fill(#FFF7C9);
  textLeading(80);
  textFont(helveticaBold);
  textSize(17);
  text(band, 55, 80);
  textFont(helvetica);
  textSize(17);
  text(title, 355,80);
  
  //Triangle
  noFill();
  stroke(#FFF7C9);
  strokeWeight(9);
  triangle(300,183,419,390,180,389);
  
  //Left side line
  fill(#FFF7C9);
  noStroke();
  beginShape();
  vertex(0,294);
  vertex(234,294);
  vertex(227,306);
  vertex(0,306);
  endShape();
  
  colorMode(HSB);
  noStroke();
  fill(randomC);
  quad(355,270,600,270,600,280,360,280);
  fill(randomC);
  quad(360,280,600,280,600,290,366,290);
  fill(randomC);
  quad(366,290,600,290,600,300,372,300);
  fill(randomC);
  quad(372,300,600,300,600,310,378,310);
  fill(randomC);
  quad(378,310,600,310,600,320,384,320);
}

void mousePressed(){
redraw();
}

```

I want these quads to change their colors every time I press the button:

```auto
  fill(randomC);
  quad(355,270,600,270,600,280,360,280);
  fill(randomC);
  quad(360,280,600,280,600,290,366,290);
  fill(randomC);
  quad(366,290,600,290,600,300,372,300);
  fill(randomC);
  quad(372,300,600,300,600,310,378,310);
  fill(randomC);
  quad(378,310,600,310,600,320,384,320);

```

I under I need to make randomC different each time? Also, currently the redraw() function I have there doesn’t do anything.

Thanks for any help!

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 5, 2019, 1:41am UTC](https://discourse.processing.org/t/how-to-randomize-colors/16136/2 "2019-12-05T01:41:22Z")

</div>

> [@masterU](#):
>
> randomC = color(random(1,360),random(1,360),random(1,360));

Repeat this line in mousePressed

---

<div class="post-metadata">

### Author: ![masterU](https://avatars.discourse-cdn.com/v4/letter/m/a88e4f/32.png) [@masterU](https://discourse.processing.org/u/masterU)
#### Post date: [December 5, 2019, 1:57am UTC](https://discourse.processing.org/t/how-to-randomize-colors/16136/3 "2019-12-05T01:57:05Z")

</div>

Thank you!

So now they are changing colors when I press the mouse, but there are 5 quads and I want each to change into a different color. How is it possible? Thank you for your time.

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [December 5, 2019, 1:58am UTC](https://discourse.processing.org/t/how-to-randomize-colors/16136/4 "2019-12-05T01:58:47Z")

</div>

> [@Chrisir](#):
>
> randomC = color(random(1,360),random(1,360),random(1,360));

Use in mousePressed()

```auto

randomC1 = color(random(1,360),random(1,360),random(1,360));
randomC2 = color(random(1,360),random(1,360),random(1,360));
randomC3 = color(random(1,360),random(1,360),random(1,360));

```

and randomC1 for the 1st quad

and randomC2 for the 2nd quads …

…

* * *

```auto
  fill(randomC1);
  quad(355,270,600,270,600,280,360,280);
  fill(randomC2);
  quad(360,280,600,280,600,290,366,290);
  fill(randomC3);
  quad(366,290,600,290,600,300,372,300);
  fill(randomC4);
  quad(372,300,600,300,600,310,378,310);
  fill(randomC5);
  quad(378,310,600,310,600,320,384,320);

```
