Created
September 28, 2021 08:42
-
-
Save YonatanKra/3a3b6c2862d3302cd4c626ccbe3c3feb to your computer and use it in GitHub Desktop.
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
function drawBackground(mazePaths) { | |
const ctx = canvas.getContext("2d"); | |
ctx.clearRect(0, 0, CANVAS_HEIGHT, CANVAS_WIDTH); | |
ctx.fillStyle = COLORS[BLACK]; | |
ctx.fill(mazePaths.roadsPath); | |
ctx.fillStyle = COLORS[WHITE]; | |
ctx.fill(mazePaths.wallsPath); | |
return mazePaths; | |
} | |
function generateBackground() { | |
const matrices = { | |
last: null, | |
current: null, | |
}; | |
matrices.current = new Array(MATRIX_DIMENSIONS.height) | |
.fill(0) | |
.map(() => { | |
return generateWhiteNoise(MATRIX_DIMENSIONS.width, WHITE_LEVEL); | |
}); | |
let count = 0; | |
const ITERATIONS_LIMIT = 100; | |
while ( | |
areMatricesDifferent(matrices.current, matrices.last) || | |
count > ITERATIONS_LIMIT | |
) { | |
matrices.last = matrices.current; | |
matrices.current = cellularAutomaton(matrices.last); | |
} | |
const backgroundPaths = generateBackgroundPaths(matrices.current); | |
return drawBackground(backgroundPaths); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment