lass-IterationExercise

var refresh;
var rows = 9; 
var cols = 9; 
var spacing = 55;
var xColor; 
var dudeColor; 
 
function setup() {
  createCanvas(550, 550);
  refresh = true;
  colorMode(HSB, 100); 
}
 
function draw() {
  if (refresh) {
    background(0, 0, 100); 
    var myHue = Math.random() * 100; 
    dudeColor = color(myHue, 30, 95); 
    xColor = color((myHue + 50) % 100, 40, 95); 
    fill(dudeColor); 
    stroke(100, 100, 30); 
    for(var i = 1; i <=rows; i++)
	for(var j = 1; j <= cols; j++){ 
            if(Math.random() > .1) 
              drawDude(i, j);
            else 
              drawX(i, j); 
	}
    refresh = false;
  }
}
 
function drawDude(x, y){
  stroke(0, 0, 100); 
  strokeWeight(0); 
  ellipse(x * spacing, y * spacing, 40, 40);
  ellipse(x * spacing - 4, y * spacing - 20, 10, 20); 
  ellipse(x * spacing + 9, y * spacing - 18, 10, 20); 
  strokeWeight(3); 
  ellipse(x * spacing - 10, y * spacing - 4, 2, 2); 
  ellipse(x * spacing + 10, y * spacing - 2, 2, 2); 
  strokeWeight(2); 
  ellipse(x * spacing, y * spacing + 1, 1, 6); 
  ellipse(x * spacing, y * spacing + 8, 15, 1); 
}
 
function drawX(x, y){
  stroke(xColor); 
  strokeWeight(4); 
  line(x * spacing + 5, y * spacing + 5, x * spacing - 5, y * spacing - 5); 
  line(x * spacing - 5, y * spacing + 5, x * spacing + 5, y * spacing - 5); 
}
 
function mousePressed() {
  refresh = true;
}