Tyler's Game of Life
by Tgwizman
HTML
<canvas id="screen">Gots to get a better browser, yo.</canvas>
JavaScript
var cells = {};
cells.main = {
screen: null,
screenWidth: 0,
screenHeight: 0,
context: null,
grid: [],
tmpGrid: [],
gridWidth: 0,
gridHeight: 0,
cellSize: 5,
stepTime: 200,
pause: false,
init: function() {
this.screen = document.getElementById("screen");
if (!this.screen.getContext) {
alert('Requires canvas...');
return;
}
document.getElementById("screen").width = window.innerWidth;
document.getElementById("screen").height = window.innerHeight;
this.screenWidth = document.getElementById("screen").width;
this.screenHeight = document.getElementById("screen").height;
this.gridWidth = Math.floor(this.screenWidth / this.cellSize);
this.gridHeight = Math.floor(this.screenHeight / this.cellSize);
this.context = document.getElementById("screen").getContext("2d");
if (document.location.href.split('?')[1]) {
if (document.location.href.split('?')[1] === 'gun') {
this.grid = [
[],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1],
[0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1]
];
...