Created
September 18, 2012 20:29
-
-
Save joehakimrahme/3745658 to your computer and use it in GitHub Desktop.
Colored Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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