// Starter Code for "Embedded Iteration + Randomness" var boolDoRefresh; var rand; var margin; var side; function setup() { createCanvas(400, 400); boolDoRefresh = true; margin = 10; side = (width-margin*9)/8 } function draw() { if (boolDoRefresh) { background(255); for (var row = 0; row<8; row++) { for (var col = 0; col<8; col++) { drawElem(row, col); } } boolDoRefresh = false; } } function mousePressed() { boolDoRefresh = true; } function drawElem(row, col) { var left = col*(side+margin)+margin; var top = row*(side+margin) + margin; rand = int(random(20)); if (rand == 0) { left += int(side/2); top += int(side/2); ellipse(left, top, side/2, side/2); } else rect(left, top, side, side); } |