Skip to content

Instantly share code, notes, and snippets.

@Gazzell
Last active December 13, 2018 08:14
Show Gist options
  • Save Gazzell/1150bec9234965436e94935ba482ccc1 to your computer and use it in GitHub Desktop.
Save Gazzell/1150bec9234965436e94935ba482ccc1 to your computer and use it in GitHub Desktop.
Maze
<canvas id='canvas' width='800' height='800'></canvas>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
const width = canvas.width;
const height = canvas.height;
const size = 20;
function drawRandomDiagonal(x, y) {
const start0 = Math.random() >= 0.5;
if (start0) {
ctx.moveTo(x, y);
ctx.lineTo(x + size, y + size);
} else {
ctx.moveTo(x, y + size);
ctx.lineTo(x + size, y);
}
ctx.stroke();
}
ctx.lineWidth = 2;
for (let x = 0; x < width; x += size) {
for (let y = 0; y < height; y += size) {
drawRandomDiagonal(x, y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment