Skip to content

mrfrac/game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dependencies Status

Conway's Game of Life

Simple realization of Game of Life.

You can play it here.

Usage example

You can see it here.

Canvas

<canvas id="gameCanvas" width="800" height="400"></canvas>

JavaScript

Somewhere in html>head:

<script src="./game-of-life.umd.js"></script>

Somewhere in JS code:

const params = {
    cols: 400, // matrix size: 400x400
    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;
}

Thanks for your attention ;)