I had lotsa examples of grids online. Here's 1 of them:
http://studio.processingtogether.com/sp/pad/export/ro.98-pSvW97Q-RE/latest
However, tfguy44's algorithm goes straight to the point!
Well, I've mixed mine code + tfguy44's and come up with this 1 below.
It works as a separate subroutine to get ya a checkerboard
PImage according to passed parameters:
// http://forum.processing.org/topic/code-to-generate-a-checkerboard-pattern
PImage boardImg;
void setup() {
size(800, 600);
noLoop();
imageMode(CENTER);
boardImg = createCheckerBoard();
}
void draw() {
background(0);
translate(width>>1, height>>1);
image(boardImg, 0, 0);
}
PImage createCheckerBoard() {
final short w = 640, h = 360, d = 20;
final color on = 0200, off = 0100, a = 0300;
return createCheckerBoard(w, h, d, on, off, a);
}
PImage createCheckerBoard(int w, int h, int d, color on, color off, color a) {
final int cols = w/d, rows = h/d;
final PGraphics pg = createGraphics(w, h, JAVA2D);
pg.beginDraw();
pg.rectMode(CORNER);
pg.noStroke();
pg.fill(on, a);
pg.background(off, a);
for (int r = 0; r != rows; ++r) for (int c = 0; c != cols; ++c)
if ( (r+c & 1) == 0 ) pg.rect(c*d, r*d, d, d);
pg.endDraw();
return pg.get();
}