Skip to content

A library to easily program and render life-like cellular automata.

License

Notifications You must be signed in to change notification settings

tarunbatra/zindagi

Repository files navigation

Zindagi

build status coverage status npm version license

Zindagi is a library to easily program and render life-like cellular automatas including but not limited to Highlife and Conway's Game of Life.

Usage

import { Zindagi } from 'zindagi';        // use ES modules
// const { Zindagi } = require('zindagi); // or CommonJS

const life = new Zindagi({
  // Life-like rule
  rules: 'S23/B3',
  // Flag to enable alive cells to re-appear on
  // the other side of the board in case of overflow
  stitchedEdges: true,
  // Symbols to represent alive and dead cells in initState param
  symbols: {
    alive: '0',
    dead: '.'
  },
  // Initial state of the automata
  initState: `..........
              .0........
              ..00......
              .00.......
              ..........
              ..........
              ..........
              ..........`
});

// play for 1000 generations
const generations = life.live(1000);

// in built method to render the automata to console/terminal
life.render(generations, {
    alive: '⬛️',            // represent alive cells with black block
    dead: '⬜️',             // represent dead cells with white block
    timePerGeneration: 0.5, // 0.5 seconds per generation
});

Output

Example Output

Install

npm install zindagi

Documentation

This is a list of the methods supproted. A detailed documentation is available in the documentation section of the homepage.

Method Description
.live(n) Returns an iterator of the current state plus n subsequent states
.skip(n) Returns the current state after moving ahead n states
.reset() Resets the current state to the initState
.toString(opts) Returns the current state represented as a formatted string
.render(iterator, opts) Renders a cellular automata in console using options

TODO

  • Documentation
  • Tests
  • Optimizations
  • HashLife implementation

Contributions are welcome!