The problem is that the draw()
function goes through your for loop
and then uses the end result for the value of color
, which is the last value in your array, as the color
that it passes into your function. In other words, your GUI is basically frozen or locked while the for loop
runs so the intermediate values, even though they are considered inside the loop, don't have any affect on whatever is being drawn on the screen.
Simplify your draw()
function by removing the loop and doing something like the example code below (I used your array of colors
for this example):
int colorCounter;
void setup()
{
// slowed down the frameRate so you can see the effect of colors changing.
frameRate(5);
colorCounter = 0;
}
void draw()
{
color[] myColors = new color[7];
myColors[0] = color(208, 102, 155);
myColors[1] = color(64, 161, 177);
myColors[2] = color(99, 153, 98);
myColors[3] = color(101, 102, 156);
myColors[4] = color(255, 204, 87);
myColors[5] = color(255, 154, 22);
myColors[6] = color(255, 53, 41);
fill(myColors[colorCounter]);
ellipse(50, 50, 50, 50);
println(colorCounter);
// using % to wrap around and avoid NPE
colorCounter = (colorCounter + 1) % myColors.length;
}
It will help to remember that draw()
itself is an infinite loop so no need to add other loops inside of it. If you think you need a loop inside draw()
then more often than not, you need to rethink your strategy because in most cases, you can just create a counter, like colorCounter
in this example, and use it to control whatever it is you want to control within the draw()
function.