void setup() { size(600, 600); noLoop(); // Draw only once } void draw() { background(255); // White background float minHeight = height / 4.0; // Ensuring at least 4 rows float y = 0; for (int i = 0; i < 4; i++) { float h = random(minHeight * 0.8, minHeight * 1.2); // Slight variation in row height if (i == 3) h = height - y; // Ensure last row fits perfectly drawRow(0, y, width, h); y += h; } } void drawRow(float x, float y, float w, float h) { if (w > 80 && random(1) > 0.3) { // Split into multiple columns within the row float startX = x; while (startX + 80 < x + w) { // Ensure minimum width of 80 float rectW = random(80, (x + w - startX) / 2); if (startX + rectW > x + w - 80) rectW = x + w - startX; // Fit last column drawRectangle(startX, y, rectW, h); startX += rectW; } } else { drawRectangle(x, y, w, h); } } void drawRectangle(float x, float y, float w, float h) { stroke(0); strokeWeight(8); fill(getMondrianColor()); rect(x, y, w, h); } color getMondrianColor() { color[] palette = {color(255, 0, 0), color(0, 0, 255), color(255, 255, 0), color(255)}; return palette[int(random(palette.length))]; }