zindagi

Zindagi is a library to program life-like cellular automata like Conway's Game of Life

Usage no npm install needed!

<script type="module">
  import zindagi from 'https://cdn.skypack.dev/zindagi';
</script>

README

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

TODO

  • Documentation
  • Tests
  • Optimizations