xxxxxxxxxx
45
function piet(x0, y0, x1, y1, N) {
if (N == 0) {
let sw = 10; //this is the stroke width for the rectangle's border
let alpha = 255;
let c = [[255,0,0,alpha], [0,0,255,alpha], [0,255,255,alpha], [255,255,0,alpha] ];
c = [[46,49,120,alpha],[50, 103, 115,alpha], [143, 140, 140,alpha], [164, 191, 63,alpha], [242, 160, 61,alpha] ,[242, 80, 65,alpha],[48,37,41,alpha],[232,174,138,alpha]];
fill(c[int(random(c.length))]);
stroke(0,0,0,alpha);
// noStroke();
strokeWeight(sw);
rect (x0, y0, x1-x0, y1-y0);
} else {
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
}
}
function setup() {
createCanvas(windowWidth, windowHeight);
drawingContext.shadowOffsetX = 1;
drawingContext.shadowOffsetY = -1;
drawingContext.shadowBlur = 5;
drawingContext.shadowColor = color(0,0,0,50);
piet(0,0,width,height,2);
}
function draw() {
// background(255,255,255,10);
// piet(0,0,width,height,4);
}
function keyPressed()
{
if( key == 's' ){
save("output.png");
}
}