/* Reference: https://makezine.com/2011/05/11/codebox-explore-recursion-with-processing/ */   let number = 3; // Number of recursive steps   //Draw the first image function setup() { createCanvas(500, 500); piet(1, 1, 500, 500, number); } // Draw a Mondarian-inspired image using recursion function piet(x0, y0, x1, y1, N) { if (N == 0) { // Base case -- draw a colorful rectangle with a thick black border let sw = 10; //this is the stroke width for the rectangle's border let c = ['#ff0000', '#0000ff', '#ffff00', '#ffffff']; //Mondarian color palatte fill(c[int(random(c.length))]); stroke(0); strokeWeight(sw); rect (x0, y0, x1-x0, y1-y0); return; } else { //Recursive step -- recursively break the current rectangle into 4 new random rectangles let i = int(random(x0, x1)); //Pick a random x coordinate inside the current rectangle let j = int(random(y0, y1)); //Pick a random y coordinate inside the current rectangle piet(x0, y0, i, j, N-1); // Recurse on upper left rectangle piet(i, y0, x1, j, N-1); // Recurse on upper right rectangle piet(x0, j, i, y1, N-1); // Recurse on lower left rectangle piet(i, j, x1, y1, N-1); // Recurse on lower right rectangle return; } //save("mondorian.png"); }   // keep draw() here to continue looping while waiting for keys function draw() { }   //Draw a new image each time a key is pressed function keyPressed() { background(0); piet(1, 1, 500, 500, number); }