xxxxxxxxxx
28
/*
Iteration with a "for" loop to construct repetitive forms.
loop syntax works like this:
for (const i of range(number-of-times-to-repeat)){
... loop body (i.e., the steps to be repeated)
}
... rest of program
*/
function range(start, stop, step=1) {
let rng = [];
if (stop===undefined) [start, stop] = [0, start];
for (let i=start; step>0 ? i<stop : i>stop; i+=step) rng.push(i);
return rng;
}
function setup() {
createCanvas(200, 200);
background(0)
fill(255, 10) // use a low-opacity shade of white
for (const i of range(4)){
print(`drawing square #`, i)
square(25,25,100)
}
}