-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
54 lines (45 loc) · 1.17 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
<html>
<head>
<!-- Load WebAssembly module -->
<script type="text/javascript" src="wasm_life_bindings.js" defer></script>
<style>
body {
background-color: black;
}
#cycle {
color: green;
}
</style>
</head>
<body>
<div id="life">
<pre id="cycle"></pre>
</div>
<canvas id="canvas" width="1500" height="900"></canvas>
<script defer>
// wait for resources to load
window.addEventListener("DOMContentLoaded", async function () {
// Wait for module to initialize,
const {
randomize,
calculate_next_generation,
renderPixels,
GRID_WIDTH,
GRID_HEIGHT,
BOX_SIZE,
} = await createModule();
const canvas = document.getElementById("canvas");
canvas.width = GRID_WIDTH * BOX_SIZE;
canvas.height = GRID_HEIGHT * BOX_SIZE;
randomize();
let cycle = 1;
setInterval(() => {
cycle++;
calculate_next_generation();
renderPixels();
document.getElementById("cycle").innerHTML = cycle;
}, 200);
});
</script>
</body>
</html>