https://github.com/semibran/node-life
:seedling:tiny update function for life-like cellular automata
https://github.com/semibran/node-life
cellular-automata game-of-life life
Last synced: 8 months ago
JSON representation
:seedling:tiny update function for life-like cellular automata
- Host: GitHub
- URL: https://github.com/semibran/node-life
- Owner: semibran
- License: mit
- Created: 2018-03-08T07:38:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T21:17:18.000Z (about 8 years ago)
- Last Synced: 2025-02-12T18:59:21.537Z (over 1 year ago)
- Topics: cellular-automata, game-of-life, life
- Language: JavaScript
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# life
> tiny update function for [life-like cellular automata]
```js
import update from "life"
let world = {
rule: { birth: [ 3 ], survival: [ 2, 3 ] },
cells: [ 1, 0, 1, 1, 1, 2 ]
}
world.cells = update(world.cells, world.rule)
console.log(world.cells)
// -> [ 0, 1, 1, 1, 2, 1 ]
```
## usage
[![npm badge]][npm package]
### `update(cells, rule) -> result`
Receives a list of living `cells` and updates it using `rule`. Returns an updated cell list of the same form as `cells`.
* `cells`: A list of the form `[ x0, y0, x1, y1, ...xn, yn ]` where each `x, y` pair represents a living cell
* `rule`: A map of the form `{ birth: [ ...neighborCount ], survival: [ ...neighborCount ] }` indicating the outcome when those criteria are met
[npm package]: https://www.npmjs.com/package/life
[npm badge]: https://nodei.co/npm/life.png?mini
[life-like cellular automata]: https://en.wikipedia.org/wiki/Life-like_cellular_automata