You'll get a huge speed up merely by caching the $("canvas")
value:
var canvas = $("canvas");
canvas.clearCanvas();
for(var x = 0; x < colorMatrix.length; x += size) {
for(var y = 0; y < colorMatrix[0].length; y += size) {
canvas.drawRect({
fillStyle: '#' + colorMatrix[x][y],
x: (x), y: (y),
width: size,
height: size,
fromCenter: false
});
}
}
But if you really want to improve performance, you should use the draw method and put your entire loop within that function so you can use the raw canvas
drawing API which will let you draw things faster.