One of John Conway's great contributions to the field of combinatorial game theory, as well as one of his many regrets.
This implementation of the Game of Life is projected onto a toroidal surface.
Take a look at the project site.
To embed the Game of Life on your website, for whatever reason, first add the scripts in the lib
directory:
<script type="text/javascript" src="lib/Game.js"></script>
<script type="text/javascript" src="lib/Board.js"></script>
<script type="text/javascript" src="lib/Cell.js"></script>
Use a custom script to initialize a GameOfLife.Game
object:
GameOfLife.game = new GameOfLife.Game(options);
The constructor accepts an options hash, which may contain the following properties:
The number of rows on the board; default 30
The number of columns on the board; default 30
The probability that each cell will be live when generated; default .3
The DOM element into which the board will be appended
The DOM element which, when clicked, will clear the board
A DOM element which will be updated to display how many in-game generations have passed
A DOM element which, when clicked, will reset the game
A DOM element which, if the game is paused, will progress the game by one generation
A DOM element which will start or pause the game
The time, in milliseconds, between each game tick; default 100
A boolean specifying whether cells may be toggled by clicking
DOM elements which are not present in the options hash will be generated by the game. They may be accessed through the following functions:
Game.prototype.getBoardElement();
Game.prototype.getCounterElement();
Game.prototype.getResetElement();
Game.prototype.getTickElement();
Game.prototype.getToggleElement();
Style the board with CSS rules for the following classes. Style should be limited to visual effects; page flow should not be modified:
.gol-board {
/*the board*/
}
.gol-row {
/*a row of cells on the board*/
}
.gol-cell {
/*a cell on the board*/
}
.live {
/*a live cell*/
}
.active {
/*the toggleElement when the game is running*/
}
The project site is made with Skeleton, which is released by David Gamache under the MIT license.
It makes use of icons from Font Awesome, which are released under the SIL Open Font License.