/
programming.html
117 lines (95 loc) · 3.71 KB
/
programming.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- Bootstrap slider theme -->
<link rel="stylesheet" href="javascript/bootstrap-slider-4.0.1/css/bootstrap-slider.css">
<!-- Bootstrap slider JavaScript -->
<script src="javascript/bootstrap-slider-4.0.1/js/bootstrap-slider.js"></script>
<!-- GOFL JavaScript -->
<script src="javascript/life.js"></script>
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-93172400-1', 'auto');
ga('send', 'pageview');
</script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Conway's Game of Life - About This Game of Life</title>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./"><img style="margin-top: -10px" width="40" height="40" src="images/brand.png"></a>
<p class="nav navbar-text"><b>Conway's Game of Life</b></p>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="introduction-1.html">Introduction</a></li>
</ul>
<ul class="nav navbar-nav">
<li><a href="catalogue.html">Explore</a></li>
</ul>
<ul class="nav navbar-nav">
<li><a href="http://github.com/coderrik/game-of-life">GitHub</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="about-this-game-of-life.html">About</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="page-header">
<h1>Programming</h1>
</div>
<pre>
// game of life algorithm
advance : function() {
for(var x = 0; x < this.width; x++) {
for(var y = 0; y < this.height; y++) {
var sum = 0;
for(var col = -1; col <= 1; col++) {
for(var row = -1; row <=1; row++) {
var xcoord = x+col;
var ycoord = y+row;
if(xcoord >= 0 && xcoord < this.width && ycoord >= 0 && ycoord < this.height) {
sum += this.cells[this.active][xcoord][ycoord];
}
}
}
if(sum == 3) {
this.cells[1-this.active][x][y] = 1;
} else if(sum == 4) {
this.cells[1-this.active][x][y] = this.cells[this.active][x][y];
} else {
this.cells[1-this.active][x][y] = 0;
}
}
}
this.active = 1-this.active;
this.generation++;
}
</pre>
</div>
</body>
</html>