https://github.com/tarunbatra/zindagi
A library to easily program and render life-like cellular automata.
https://github.com/tarunbatra/zindagi
cellular-automata cellular-automaton conways-game-of-life conwaysgameoflife game-of-life
Last synced: 3 months ago
JSON representation
A library to easily program and render life-like cellular automata.
- Host: GitHub
- URL: https://github.com/tarunbatra/zindagi
- Owner: tarunbatra
- License: mit
- Created: 2020-11-01T22:56:27.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-09T22:41:09.000Z (almost 5 years ago)
- Last Synced: 2025-04-29T02:06:43.782Z (6 months ago)
- Topics: cellular-automata, cellular-automaton, conways-game-of-life, conwaysgameoflife, game-of-life
- Language: JavaScript
- Homepage: https://tarunbatra.com/zindagi
- Size: 973 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Zindagi][logo]][docs]
[![build status][build-image]][build-url]
[![coverage status][codecov-image]][codecov-url]
[![npm version][npm-image]][npm-url]
![license][license-image]Zindagi is a library to easily program and render [life-like cellular automatas][life-like-wiki] including but not limited to Highlife and [Conway's Game of Life][gol-wiki].
## Usage
```js
import { Zindagi } from 'zindagi'; // use ES modules
// const { Zindagi } = require('zindagi); // or CommonJSconst 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][example-output-gif]## Install
```
npm install zindagi
```## Documentation
This is a list of the methods supproted. A detailed documentation is available in the [documentation section][zindagi-class-doc] of the homepage.|Method|Description|
|:-----|:----------|
|`.live(n)`|Returns an [iterator][mdn-iterator-doc] 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
- [x] Documentation
- [x] Tests
- [ ] Optimizations
- [ ] HashLife implementation
__Contributions are welcome!__
[logo]: https://res.cloudinary.com/tbking/image/upload/v1604344754/zindagi/zindagi-logo.gif
[docs]: https://tarunbatra.com/zindagi[build-image]:https://img.shields.io/github/workflow/status/tarunbatra/zindagi/CI?label=CI&logo=github&style=flat-square
[build-url]:https://github.com/tarunbatra/zindagi/actions?query=workflow%3ACI
[codecov-url]: https://codecov.io/gh/tarunbatra/zindagi
[codecov-image]: https://img.shields.io/codecov/c/gh/tarunbatra/zindagi?logo=codecov&style=flat-square
[npm-image]: https://img.shields.io/npm/v/zindagi.svg?style=flat-square&color=magenta
[npm-url]: https://www.npmjs.com/package/zindagi
[license-image]: https://img.shields.io/github/license/tarunbatra/zindagi?color=pink&style=flat-square[life-like-wiki]: https://en.wikipedia.org/wiki/Life-like_cellular_automaton
[gol-wiki]: https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
[example-output-gif]: https://res.cloudinary.com/tbking/video/upload/e_loop/v1604362000/zindagi/glider-example.gif[zindagi-class-doc]: https://tarunbatra.com/zindagi/Zindagi.html
[mdn-iterator-doc]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol