Arrays and colors

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

OpenProcessing.org/sketch/473642

1 Like

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!

Processing.org/reference/modulo.html
Processing.org/reference/noLoop_.html
Processing.org/reference/mousePressed_.html

2 Likes