/**
* Checkerboard.
*
*
Elie Zananiri
* CART 253, Winter 2008
*/
/*------- initialization ------------*/
void setup() {
size(300, 300);
background(255);
noStroke();
}
/*------ function definitions -------*/
// draws a checkerboard pattern
void drawPattern() {
int cellSize = 20; // size of our rectangles
boolean white = true; // flag to indicate the fill
boolean oddColumn = true; // flag to indicate the column type
// walk across the x-axis
for (int x=0; x < width ; x = x+cellSize) {
// walk down the y-axis
for (int y=0; y < height; y = y+cellSize) {
if (white) {
fill(255);
} else {
fill(0);
}
rect(x, y, cellSize, cellSize);
// toggle the fill flag
white = !white;
}
// flip the flag that tells us whether we're starting an even or odd column
oddColumn = !oddColumn;
// make sure that each successive column starts with a different fill
white = oddColumn;
}
}
/*------ main loop ------------------*/
void draw() {
drawPattern();
}