UNPKG

data-fns

Version:

This library provides utility functions for working with array data that are useful in many contexts, including creative coding. It offers generic functions that perform common operations such as offsetting an array, generating an array based on a callbac

29 lines (28 loc) 1.25 kB
export declare type CellularAutomataRuleset = [number, number, number, number, number, number, number, number]; export declare type BoundaryFunction = (index: number, length: number) => number; /** * Generates a new sequence using a one-dimensional cellular automaton. * @param sequence The initial sequence. * @param ruleset The ruleset for the cellular automaton. * @param boundaryFn The boundary function to use. * @returns The resulting sequence. * @example * * generateSequence(10, sequence, cellularAutomata) * // Returns [ * // [0, 0, 0, 0, 1, 0, 0, 0], * // [0, 0, 0, 1, 1, 1, 0, 0], * // [0, 0, 1, 1, 0, 0, 1, 0], * // [0, 1, 1, 0, 1, 1, 1, 1], * // [0, 1, 0, 0, 1, 0, 0, 0], * // [1, 1, 1, 1, 1, 1, 0, 0], * // [1, 0, 0, 0, 0, 0, 1, 1], * // [0, 1, 0, 0, 0, 1, 1, 0], * // [1, 1, 1, 0, 1, 1, 0, 1], * // [0, 0, 0, 0, 1, 0, 0, 1], * // ] * * @complexity This function has a time complexity of O(n), where n is the length of the input sequence, and * a space complexity of O(n), where n is the length of the input sequence. */ export declare const cellularAutomata: (sequence: Array<number>, ruleset?: CellularAutomataRuleset, boundaryFn?: BoundaryFunction) => Array<number>;