Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created July 31, 2021 06:55
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 YonatanKra/30fa243701d3815f821067945f34a34d to your computer and use it in GitHub Desktop.
Save YonatanKra/30fa243701d3815f821067945f34a34d to your computer and use it in GitHub Desktop.
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