I am trying to create an array of vertices, and then run the 'rect' function over this array to display an arbitrary amount of rectangles. Right now, I have:
var vertices = new Array();
function setup() {
createCanvas(600, 600);
...
iter(width/2 - c/2, height/2 - c/2, c);
var i;
for (i = 0; i < vertices.length; i++) {
fill(200);
rect(vertices[i]);
}
}
And then:
function iter(x, y, len) {
r_1 = random(0, 1);
if (r_1 < 0.5){
vertices.push(x, y - len*0.5, len*0.5, len*0.5);
}
}
I have seen lots about using map or foreach to run functions over arrays but I don't know why this doesn't work (specifically, using a for loop to run a function over an array). I am obviously very new to all this stuff! An explanation of what I seem to misunderstand would be very much appreciated.
Thanks