Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Created September 27, 2021 15:28
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/cca327e6c30b12982fb27a96b97013f8 to your computer and use it in GitHub Desktop.
Save YonatanKra/cca327e6c30b12982fb27a96b97013f8 to your computer and use it in GitHub Desktop.
function generateBackgroundPaths(matrix) {
const wallsPath = new Path2D();
const roadsPath = new Path2D();
const mazePaths = {
wallsPath,
roadsPath,
};
matrix.forEach((pixelsRow, rowIndex) => {
const y = rowIndex * PIXEL_RATIO;
pixelsRow.forEach((pixel, pixelIndex) => {
const x = pixelIndex * PIXEL_RATIO;
const currPath = pixel === BLACK ? roadsPath : wallsPath;
currPath.rect(x, y, PIXEL_RATIO, PIXEL_RATIO);
});
});
return mazePaths;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment