harsh-IterationExercise

var boolDoRefresh;
 
function setup() {
  createCanvas(400, 400);
	background(255);
  boolDoRefresh = true;
}
 
function draw() {
	var border = 4;
	var numRects = 20;
	var gridWidth = width/numRects;
	var gridHeight = height/numRects;
	var numCircles = numRects;
 
	var rectGrid = [];
	var randomNums =[];
 
 
  if (boolDoRefresh) {
 
		background(255, 153, 153);
 
		for(var k=0; k<numCircles; k++){
			var newRandomNumX = Math.round(random(0,numRects));
			var newRandomNumY = Math.round(random(0,numRects));
			randomNums.push([newRandomNumX,newRandomNumY]);
		}		
		for(var i=0; i<numRects; i++){		
			for(var j=0; j<numRects; j++){
				var rowCol = [i,j];	
				var isCircle = false;
 
				for(var k=0; k<randomNums.length-1;k++){
					var curRandom = randomNums[k];					
					if(curRandom[0] == rowCol[0] && curRandom[1] == rowCol[1]){
						isCircle = true;
					}				
				}
 
				if(isCircle == false){
					push();
					noStroke();
					fill(255, 255, 153);
					rect(i*gridWidth+border,j*gridHeight+border,gridWidth-border*2,gridHeight-border*2);
					pop();
				}
 
				else{
					push();
					noStroke();
					fill(0, 102, 153);
					ellipse(i*gridWidth+gridWidth/2,j*gridHeight+gridWidth/2,gridWidth/2,gridHeight/2);
					pop();
				}
			}
		}
    boolDoRefresh = false;
	}
}
 
function mousePressed() {
  boolDoRefresh = true;
}