xxxxxxxxxx
38
/*
Based on the Recursive Squares example from Chapter 8: Drawing with Recursion, Processing: Creative Coding and Generative Art in Processing 2, 2013, by Ira Greenberg, Dianna Xu, Deepak Kumar
*/
let minSize = 100;
function setup() {
createCanvas(windowWidth, windowHeight);
initialize();
}
function initialize() {
background(0);
rectMode(CENTER);
noFill();
stroke(255);
let squareSize = min(width, height) / 2;
drawSquare(width / 2, height / 2, squareSize);
}
function drawSquare(x, y, size) {
square(x, y, size);
if (size >= minSize) {
let newSize = size / 2;
drawSquare(x - newSize, y - newSize, newSize);
drawSquare(x + newSize, y - newSize, newSize);
drawSquare(x - newSize, y + newSize, newSize);
drawSquare(x + newSize, y + newSize, newSize);
}
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
initialize();
}