shuann-IterationExercise

GIF:

// Starter Code for "Embedded Iteration + Randomness"
var boolDoRefresh;
var gridSize = 45;
var offset = 5;
 
function setup() {
  createCanvas(400, 400);
  boolDoRefresh = true;
}
 
function draw() {
  if (boolDoRefresh) {
    // DRAW STUFF HERE....
    background(240);
    for (var x = offset*4; x <= width - gridSize; x += gridSize){
      for (var y = offset*4; y <= height - gridSize; y += gridSize) {
        stroke("pink");
        fill("white");
        var rand = random();
        if (rand <= 0.05){
          ellipse(x + (gridSize-offset)/2, y + (gridSize-offset)/2, gridSize/2);
        } else {
          rect(x, y, gridSize-offset, gridSize-offset);
        }
      }
    }
    boolDoRefresh = false;
  }
}
 
function mousePressed() {
  boolDoRefresh = true;
}