canvas - random colored pixels

by Amanda Williamson

HTML

<canvas id="canvas" height="300" width="300"></canvas>

JavaScript

var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var x = 0;
var y = 0;

for(x = 0; x < 100; x += 5) {
  for (y = 0; y < 100; y += 5) {
    ctx.moveTo(x,y);
    ctx.fillStyle = getRandomColor();
    ctx.fillRect(x,y,5,5);
  }
}

function getRandomColor(){
  var r = 255*Math.random()|0,
      g = 255*Math.random()|0,
      b = 255*Math.random()|0;
  return 'rgb(' + r + ',' + g + ',' + b + ')';
}