Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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