Skip to content

A JavaScript implementation of Conway's Game of Life and other types of cellular automata.

Notifications You must be signed in to change notification settings

mnbond/cellular-automata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cellular automaton

A JavaScript implementation of Conway's Game of Life and other types of cellular automata. View demo here: codepen.io.

Screenshots

Instructions

  1. Add JavaScript code containing class CellularAutomata in an HTML document:

    <script src="js/cellular-automata.js" type="text/javascript"></script>
  2. Add HTML element for the game in body section:

    <div id="ca-container"></div>
  3. Сreate an instance of class CellularAutomata after the DOMContentLoaded event and call method start:

    document.addEventListener("DOMContentLoaded", () => {
        ca = new CellularAutomata("ca-container", 6, 100);
        ca.start();
    });

    Class CellularAutomata constructor parameters:

    • containerId — ID of HTML element for the game;
    • cellSizePx — size of cell in pixels, default 10 pixels;
    • speedMs — iteration time in milliseconds, default 1000 milliseconds.

Adding new types of cellular automata

To add new types modify this method of class CellularAutomata:

class CellularAutomata {
    ...
    setDefaultProperties() {
        ...
        this.settings = {
            ...
            types: [
                {
                    name: "B3S23",
                    rules: { },
                    genFirstState: (cells, cellsCountX, cellsCountY) => { }
                }

About

A JavaScript implementation of Conway's Game of Life and other types of cellular automata.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published