Noncommital Premarital Mischief

    @sondregj/conway
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    🧫

    Conway

    Cellular Automata

    npm (latest) npm bundle size GitHub contributors License Gitmoji

    A simple cellular automaton implementation, in TypeScript.

    Usage

    Install by running npm install @sondregj/conway

    import { advance } from '@sondregj/conway'
     
    const world = {
        cells: [
            [{ alive: false }, { alive: false }, { alive: true }],
            [{ alive: true }, { alive: false }, { alive: true }],
            [{ alive: false }, { alive: true }, { alive: true }],
        ],
    }
     
    const day1 = advance(world)

    You can also define custom rule functions.

    import { advance } from '@sondregj/conway'
     
    const world = {
        cells: [
            [{ alive: false }, { alive: false }, { alive: true }],
            [{ alive: true }, { alive: false }, { alive: true }],
            [{ alive: false }, { alive: true }, { alive: true }],
        ],
    }
     
    const rules = (board, cell, x, y) => !cell.alive
     
    const day1 = advance(world, rules)

    A convenience function for initializing boards is also included.

    import { initializeBoard, advance } from '@sondregj/conway'
     
    const genesis: Board = initializeBoard(64, 64, { random: true })
     
    const day1 = advance(genesis)

    The following TypeScript types are included.

    import { Board, BoardTick, Cell, RuleFunction } from '@sondregj/conway'
     
    const world: Board = {
        cells: [
            [{ alive: false }, { alive: false }, { alive: true }],
            [{ alive: true }, { alive: false }, { alive: true }],
            [{ alive: false }, { alive: true }, { alive: true }],
        ],
    }
     
    const cell: Cell = { alive: true }
     
    const advance: BoardTick = (board: Board): Board => board
     
    const rules: RuleFunction = (board: Board, cell: Cell, x: number, y: number): boolean =>
        true

    License

    MIT © 2019 Sondre Gjellestad

    Install

    npm i @sondregj/conway

    DownloadsWeekly Downloads

    6

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    8.26 kB

    Total Files

    15

    Last publish

    Collaborators

    • avatar