life

1.0.0 • Public • Published

life

tiny update function for life-like cellular automata

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

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

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i life

      Weekly Downloads

      4

      Version

      1.0.0

      License

      MIT

      Unpacked Size

      8.27 kB

      Total Files

      12

      Last publish

      Collaborators

      • semibran