# Arrays and colors

**URL:** <https://discourse.processing.org/t/arrays-and-colors/11526>\
**Category:** Coding Questions\
**Created:** [May 23, 2019, 10:36pm UTC](https://discourse.processing.org/t/arrays-and-colors/11526 "2019-05-23T22:36:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darius](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Darius](https://discourse.processing.org/u/Darius)\
**Post date:** [May 23, 2019, 10:36pm UTC](https://discourse.processing.org/t/arrays-and-colors/11526/1 "2019-05-23T22:36:39Z")

</div>

Hi All, I am very new in processing and I am trying to use an array to change the color of my background color by clicking with the mouse to use numbers from 0 to 4. This seems not really working on my sketch, any suggestion? Thanks!

color [] colors = new color[4];

int total=0;

void setup() {  
size(500, 500);

colors[0] = color(0, 177, 235);  
colors[1] = color(254, 199, 0);  
colors[2] = color(232, 42, 5);  
colors[3] = color(162, 198, 23);

for (int i=0; i\<colors.length; i++) {  
background(colors[int(total)]);  
}  
}

void draw() {  
if (mousePressed == true) {  
background(colors[int(total+1)]);  
}  
}

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 23, 2019, 10:42pm UTC](https://discourse.processing.org/t/arrays-and-colors/11526/2 "2019-05-23T22:42:31Z")

</div>

[OpenProcessing.org/sketch/473642](http://OpenProcessing.org/sketch/473642)

---

<div class="post-metadata">

**Author:** ![Darius](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@Darius](https://discourse.processing.org/u/Darius)\
**Post date:** [May 23, 2019, 10:55pm UTC](https://discourse.processing.org/t/arrays-and-colors/11526/3 "2019-05-23T22:55:40Z")

</div>

Hi buddy, thanks!

This is what I was looking for:) Is there anything you can explain or share in term or resource so I can understand how you built the code?

Cheers!

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 23, 2019, 10:58pm UTC](https://discourse.processing.org/t/arrays-and-colors/11526/4 "2019-05-23T22:58:55Z")

</div>

[Processing.org/reference/modulo.html](http://Processing.org/reference/modulo.html)  
[Processing.org/reference/noLoop\_.html](http://Processing.org/reference/noLoop_.html)  
[Processing.org/reference/mousePressed\_.html](http://Processing.org/reference/mousePressed_.html)
