-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
86 lines (77 loc) · 2.38 KB
/
index.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta content="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dungeon Generator</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="math.js"></script>
<script src="geometry.js"></script>
<script src="probability.js"></script>
<script src="canvas-window.js"></script>
<script src="dungeon-generator.js"></script>
<script src="dat.gui.js"></script>
<script>
const canvas = new CanvasWindow();
const settings = {
numberOfRooms: 32,
circleRadius: 8,
minRoomSize: 40,
maxRoomSize: 160,
gravitationalForce: 0.001,
velocityStepSize: 0.5,
maxVelocity: 16,
nearestNeighbours: 2,
regenerate: () => { } /* used for dat.gui */
};
let cancel = false;
const generate = () => {
const dungeon = new DungeonGenerator(settings);
dungeon.generate();
const drawer = new DungeonDrawer(canvas);
const animate = () => {
if(cancel)
{
return;
}
canvas.clear();
if (!dungeon.step()) {
requestAnimationFrame(animate);
}
else {
dungeon.calculateNearestNeighbours();
}
drawer.draw(dungeon);
}
animate();
}
// Hacky way to cancel the drawing
settings.regenerate = () => {
cancel = true;
setTimeout(() => {
cancel = false;
generate();
}, 100)
};
generate();
const gui = new dat.GUI();
gui.add(settings, 'numberOfRooms', 1, 400);
gui.add(settings, 'circleRadius', 1, 1024);
gui.add(settings, 'minRoomSize', 1, 200);
gui.add(settings, 'maxRoomSize', 1, 800);
gui.add(settings, 'gravitationalForce', 0.00001, 1);
gui.add(settings, 'velocityStepSize', 0.001, 1);
gui.add(settings, 'maxVelocity', 1, 100);
gui.add(settings, 'nearestNeighbours', 0, 16);
gui.add(settings, 'regenerate');
</script>
</body>
</html>