moving objects
@author
int LOOP = 50;
float rectSize = 12;
float gap = 50;
void setup(){
size(500, 500);
rectMode(CENTER);
}
void draw(){
background(255, 255, 204);
noStroke();
fill(0);
int time = frameCount % LOOP;
for(int x = -1; x <= int(width / gap) + 1; x++){
for(int y = 0; y <= int(height / gap) + 1; y++){
float w = x * gap;
if(y % 2 == 0){
w += map(time, 0, LOOP - 1, 0, gap);
fill(46, 153, 67);
} else {
w += map(time, 0, LOOP - 1, 0, -gap);
fill(110, 46, 153);
}
float h = y * gap;
rect(w, h, rectSize, rectSize);
}
}
for(int y = -1; y <= int(height / gap) + 1; y++){
for(int x = 0; x < int(width / gap) + 1; x++){
float h = (y + 0.5) * gap;
if(x % 2 == 0){
h += map(time, 0, LOOP - 1, 0, gap);
fill(46, 110, 153);
} else {
h += map(time, 0, LOOP - 1, 0, -gap);
fill(153, 46, 67);
}
float w = x * gap;
rect(w, h, rectSize, rectSize);
}
}
}