-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
69 lines (60 loc) · 2.16 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Game of Live</title>
<script src="./game-of-life.umd.js"></script>
<style>
canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.fork-me {
position: fixed;
right: 0;
top: 0;
}
</style>
</head>
<body>
<a class="fork-me" href="https://github.com/mrfrac/game-of-life"><img width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_green_007200.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
<button onclick="play()">Play</button>
<button onclick="pause()">Pause</button>
<button onclick="reset()">Reset</button>
<canvas id="gameCanvas" width="800" height="400"></canvas>
<script>
const params = {
cols: 400,
rows: 400,
color: "gray"
};
let game = new GameOfLife.Game("gameCanvas", params);
let gameStarted = undefined;
function play() {
if (!gameStarted) gameStarted = 1;
playGame();
}
function playGame() {
if (!gameStarted) return;
game.liveOut();
window.requestAnimationFrame(playGame)
}
function reset() {
pause();
params.color = '#' + (function lol(m, s, c) {
return s[m.floor(m.random() * s.length)] + (c && lol(m, s, c - 1));
})(Math, '0123456789ABCDEF', 4);
game = new GameOfLife.Game("gameCanvas", params);
}
function pause() {
gameStarted = undefined;
}
</script>
</body>
</html>