not an answer but a note. when you draw a grid with rectangles you overdraw many lines and many rectangles can be taxing to draw. a faster version is to draw the grid with lines instead.
int gridResolution;
int gridColumns;
int gridRows;
void setup() {
size(512, 512, P2D);
gridResolution = 32;
gridColumns = width / gridResolution;
gridRows = height / gridResolution;
}
void draw() {
drawGrid();
}
void drawGrid() {
stroke(0);
for(int y = 0; y <= gridRows; y++) {
line(0, y * gridResolution, width, y * gridResolution);
}
for(int x = 0; x <= gridColumns; x++) {
line(x * gridResolution, 0, x * gridResolution, height);
}
}
// smart grid of rectangles,
int x = 10, y = x, w = 27, h = w, off = 5, grid = 13, many = grid*grid;
color col1 = color(62, 219, 59);
color col2 = color(33, 181, 72);
boolean switchcol = true;
void setup() {
size(440, 440);
println("x "+x+" y "+y+" w "+w+" h "+h+" offset "+off+" grid "+grid+" many "+many);
}
void draw() {
drawGrid();
}
void selcol() {
if ( switchcol ) fill(col1);
else fill(col2);
switchcol = ! switchcol;
}
void drawGrid() {
switchcol = true;
for (int i = 0; i < many; i++) {
selcol();
rect(x+(i%grid)*(w+off), y+(floor(i/grid))*(h+off), w, h); // or any other shape/text on that position
}
}