-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoL.html
More file actions
95 lines (76 loc) · 2.87 KB
/
GoL.html
File metadata and controls
95 lines (76 loc) · 2.87 KB
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
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Conway's Game of Life</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<style type="text/css" media="screen">
body { background-color: #F9F9F9; }
.main-header h1 {
text-align: center;
}
canvas {
display: block;
/* border: 2px solid black; */
}
.canvas-control {
width: 0;
margin: 0 auto;
}
.controls {
text-align: center;
margin-top: 1rem;
}
</style>
</head>
<body>
<header class="main-header">
<h1>Conway's Game of Life</h1>
</header><!-- /main-header -->
<section class="canvas-control">
<canvas id="main-canvas">
Sorry, your browser doesn't support <pre>canvas</pre>. Please update it.
</canvas>
<section class="controls">
<button class="button toggle play">
Play
</button>
<button class="button clear">
clear
</button>
<button class="button toggle contrast">
Change Contrast
</button>
</section> <!-- /controls -->
</section> <!-- /canvas-control -->
<footer class="main-footer">
</footer>
<script src="GoL.js" type="text/javascript" charset="utf-8"></script>
<script src="Grid.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8" async defer>
(function() {
let canvasControl = document.getElementsByClassName('canvas-control')[0];
canvasControl.style.minWidth = canvas.width + 'px';
let togglePause = document.getElementsByClassName('button toggle play')[0];
togglePause.addEventListener('click', function() {
this.innerHTML = isPaused ? 'Pause' : 'Play';
isPaused = !isPaused;
});
let toggleContrast = document.getElementsByClassName('button toggle contrast')[0];
toggleContrast.addEventListener('click', function() {
// Swap canvas background color with its foreground grid color
let temp = backgroundColor;
backgroundColor = foregroundColor;
foregroundColor = temp;
});
let clearButton = document.getElementsByClassName('button clear')[0];
clearButton.addEventListener('click', function() {
isPaused = true;
togglePause.innerHTML = 'Play';
grid = initGrid(grid_size);
});
}());
</script>
</body>
</html>