-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
34 lines (23 loc) · 817 Bytes
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {
DistanceGrid,
MazeCanvasRenderer,
MazeGrid,
RecursiveBacktracker,
} from './legendary-mazes.js';
const maze = new MazeGrid(48, 32);
const builder = new RecursiveBacktracker(maze);
const distances = new DistanceGrid(maze);
const renderer = new MazeCanvasRenderer(maze, ["#111", "#765", "#aaa", "#f30", "#ff3", "#3f3", "#3ff", "#03f"]);
function build(showDistances = true) {
builder.build();
if (showDistances) {
distances.build(maze.centralCell);
renderer.setDistanceGrid(distances, { r: 256, g: 0, b: 32 }, { r: 230, g: 240, b: 255 });
}
console.log(`generated an ${maze.width}x${maze.height} pixels maze`);
}
build();
const canvas = document.getElementById('maze-canvas');
canvas.width = maze.width;
canvas.height = maze.height;
renderer.render(canvas.getContext('2d'));