Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function draw(matrix) {
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, CANVAS_HEIGHT, CANVAS_WIDTH);
ctx.beginPath();
matrix.forEach((pixelsRow, rowIndex) => {
const y = rowIndex * PIXEL_RATIO;
pixelsRow.forEach((pixel, pixelIndex) => {
const x = pixelIndex * PIXEL_RATIO;
ctx.fillStyle = COLORS[pixel];
ctx.fillRect(x, y, PIXEL_RATIO, PIXEL_RATIO);
});
});
ctx.closePath();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment