Thanks to all of you guys!
@Chrisir Your sketch gave me the solution. You misunderstood what I wanted: not the colors to appear one by one as listed, but for them to appear one by one in accordance to the array of random values. I just had to do a minor modification on your sketch, and found the solution I was looking for. But I couldn’t have done it without your help.
int[] array = new int[5];
int actionCounter = 0;
int timer;
int j;
void setup() {
size(600, 600);
background(128);
for (int i = 0; i < array.length; i++) {
array[i] = int(random(4));
}
println(array);
timer = millis();
}
void draw() {
background(128);
showAction() ;
if (millis()-timer >= 1100) {
actionCounter++;
timer = millis();
}
}
void showAction() {
if (actionCounter == 0) {
j = 0;
setColor();
rect(200, 200, 100, 100);
} else if (actionCounter == 1) {
j = 1;
setColor();
rect(200, 200, 100, 100);
} else if (actionCounter == 2) {
j = 2;
setColor();
rect(200, 200, 100, 100);
} else if (actionCounter == 3) {
j = 3;
setColor();
rect(200, 200, 100, 100);
} else if (actionCounter == 4) {
j = 4;
setColor();
rect(200, 200, 100, 100);
}
}
void setColor() {
if (array[j] == 0) {
fill(0);
rect(200, 200, 100, 100);
}
if (array[j] == 1) {
fill(255, 0, 0);
rect(200, 200, 100, 100);
}
if (array[j] == 2) {
fill(0, 255, 0);
rect(200, 200, 100, 100);
}
if (array[j] == 3) {
fill(0, 0, 255);
rect(200, 200, 100, 100);
}
if (array[j] == 4) {
fill(255);
rect(200, 200, 100, 100);
}
}