GithubHelp home page GithubHelp logo

tarunbatra / zindagi Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 996 KB

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

Home Page: https://tarunbatra.com/zindagi

License: MIT License

JavaScript 100.00%
game-of-life conways-game-of-life cellular-automata cellular-automaton conwaysgameoflife

zindagi's Introduction

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!

zindagi's People

Contributors

tarunbatra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.