I started working this up before the last post … so i’ll go ahead and share this method as well.
using millis() like in @Chrisir example is more accurate than this method btw.
ArrayList<ColorSwatch> colorSwatches = new ArrayList();
color[] cols = {#22223B, #4A4E69, #9A8C98, #C9ADA7, #F2E9E4};
int idx, counter = 0;
void setup() {
size(600, 600);
rectMode(CENTER);
for (int i = 0; i < 5; i++) {
colorSwatches.add(new ColorSwatch(new PVector(width*0.5, height*0.5), cols[int(random(4))], 100));
}
}
void draw() {
background(13, 17, 21);
textSize(100);
updateSwatch();
colorSwatches.get(idx).display();
counter++;
}
void updateSwatch() {
if (counter % 100 == 0) {
if (idx >=4) {
idx = 0;
counter = 0;
} else {
idx++;
}
}
}
class ColorSwatch {
PVector pos;
color col;
int scl;
ColorSwatch(PVector p, color c, int s) {
pos = p;
col = c;
scl = s;
}
void display() {
pushStyle();
noStroke();
fill(col);
rect(pos.x, pos.y, scl, scl);
popStyle();
}
}