Skip to content

Instantly share code, notes, and snippets.

@joehakimrahme
Created September 18, 2012 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehakimrahme/3745658 to your computer and use it in GitHub Desktop.
Save joehakimrahme/3745658 to your computer and use it in GitHub Desktop.
Colored Matrix
window.onload = function () {
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var matrix = [];
var colors = ['yellow', 'red'];
//filling the matrix with style B-)
matrix.push([1, 1, 0]);
matrix.push([0, 1, 0]);
matrix["push"]([0, 0, 1]);
var x = 50;
var y = 50;
for (var i=0; i<matrix.length; ++i) {
line = matrix[i];
for (var j=0; j<line.length; ++j) {
context.beginPath();
context.rect(x, y, 20, 20);
context.fillStyle = colors[line[j]];
context.fill();
context.stroke();
x += 20;
}
x = 50;
y += 20;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment