Hello!
I am trying to understand how a sketch works that I saw on the openprocessing.org site by Naoto Hieda.
The use of “level” in this sketch, I am not fully understanding. And it’s probably a very simple oversight on my part but here is the line:
if (level == 0 || (random(1) < 0.5 && level < 5)) {
// level < 5?? Where is level being changed to test this criteria?
///////////////////////////////////////////////////////
FULL SKETCH BELOW :
///////////////////////////////////////////////////////
const W = 600;
function setup() {
createCanvas(W, W);
background(100);
}
function draw() {
noLoop();
div(0, 0, W, 0);
}
function div(x, y, w, level) {
if (level == 0 || (random(1) < 0.5 && level < 5)) { // This is the line I'm stuck on, esp the end "level < 5"
div(x, y, w / 2, level + 1);
div(x + w / 2, y, w / 2, level + 1);
div(x + w / 2, y + w / 2, w / 2, level + 1);
div(x, y + w / 2, w / 2, level + 1);
} else {
// rect(x, y, w, w);
if (random(1) < 0.5) {
for (const r of [w / 3 * 4, w / 3 * 2]) {
arc(x, y, r, r, 0, PI / 2)
arc(x + w, y + w, r, r, PI, PI / 2 * 3)
}
} else {
for (const r of [w / 3 * 4, w / 3 * 2]) {
arc(x + w, y, r, r, PI / 2, PI)
arc(x, y + w, r, r, PI / 2 * 3, PI * 2)
}
}
}
}
Any clarification is most appreciated!
Thank you