// Example: Using for loops to draw rectangles void setup () { size(300, 300); background(10); frameRate(5); } void draw () { drawBoxes(); } // Simple function: no input, no output returned void drawBoxes () { int x; int y = 25; int maxRects = 5; int maxRows = 5; // For each row in the image... for (int row = 0; row < maxRows; row++) { x = 25; // Draw a number of squares corresponding to // that row's value (i.e., 1 square for the // first row (row 0), 2 squares for the second // row, etc...) for (int numRects = 0; numRects < (row + 1); numRects++) // To draw a "square" of squares, replace "(row + 1)" // with "maxRows" in the loop test above { fill(random(256), random(256), random(256)); rect(x, y, 50,50); x = x + 50; // Move to right of last rectangle } y = y + 50; // Move down 1 row } }