A cellular automata engine

Type Parameters

  • T

Hierarchy

  • PixelManipulator

Constructors

Properties

defaultId: number

The elm that pixelmanipulator will fill the screen with upon initialization, and what elements should return to when they are "dead". Default value is 0, an element with the color #000F

If you update this, be sure to update defaultRenderAs in renderer

elements: ElementData<T>[] = []

A low-level listing of the availiable elements.

Format is much like the argument to addMultipleElements, but is not sanitized.

frames: Uint32Array[] = ...

A List of Uint32Arrays each the length of width times height of the canvas. Frame 0 is the new frame, frame one is the prior, etc. Each item holds the element id of each element on screen, from left to right, top to bottom.

loopint: number = 0

This is the number that indicates what animation frame the iterate function is being called with.

You can use this to mannually stop the iterations like so: cancelAnimationFrame(this.loopint) (not reccommended)

mode: "paused" | "playing" = 'paused'

A string indicating weather it is currently animating or not.

It is "playing" if it is currently animating, or "paused" if not currently animating.

This has been around since early version 0, and once was the innerText value of a pause/play button!

nameAliases: Map<string, string> = ...

A mapping from old names for elements to new names for elements.

Allows a user to modify the name of an element at runtime.

onAfterIterate: (() => void) = ...

Type declaration

    • (): void
    • Called after iterate does its work.

      Returns void

onElementModified: ((id: number) => void) = ...

Type declaration

    • (id: number): void
    • Gets called after a call to modifyElement. The ID is passed as the only argument.

      Parameters

      • id: number

        The element that was modified.

      Returns void

onIterate: (() => boolean | void) = ...

Type declaration

    • (): boolean | void
    • Called before iterate does its work.

      Returns

      false to postposne iteration.

      Returns boolean | void

pixelCounts: {
    [index: number]: number;
} = {}

Number of pixels per element in the last frame

Type declaration

  • [index: number]: number
renderer: Renderer<T>

An instanace of the object that shows the state to the user.

_moore: Hitbox = ...
_wolfram: Hitbox = ...

Methods

  • Parameters

    • oldName: string

      The old name

    • newName: string

      The new name

      Adds the name to nameAliases, and ensures no alias loops are present.

    Returns void

  • Returns

    Does the cell at loc match ident?

    Parameters

    • loc: Location

      Where to confirm the element

    • id: string | number

      The elm you expect it to be

    Returns boolean

  • See

    Returns

    The state that the bitfied says this pixel should be in the next frame.

    Parameters

    • area: Location[]

      The Area to search within

    • ruleNum: number

      A bitfield of what states a pixel should live or die on.

    • search: string | number

      The element to search for

    Returns boolean

  • See

    fundamentalNewState for higher-level tool

    Returns

    number as a bitfied array, in order of the items in area, from left to right.

    That means that (fundamentalStatesWithin([loc], search) & 1) === boolToNumber(confirmElm(loc, search))

    You may want to see this page for more details on how this might be used.

    Parameters

    • area: Location[]

      Locations to look at.

    • search: string | number

      Locations to mark as a true bit.

    Returns number

  • A single frame of animation. Media functions pass this into requestAnimationFrame.

    Be careful! Calling this while mode is "playing" might cause two concurrent calls to this function. If any of your automata have "hidden state" - that is they don't represent every detail about themselves as data within the pixels - it might cause conflicts.

    Returns void

  • Returns

    null if out-of-bounds when loop setting is false, or the location (loop set to false).

    Parameters

    • loc: Location

      Location of the pixel (could be out of bounds).

    Returns null | Location

  • Returns

    Number of matching elements in moore radius

    Parameters

    • center: Location

      location of the center of the moore area

    • search: string | number

    Returns number

  • Respecting aliases, convert an element name into its number.

    Returns

    The number of the element

    Parameters

    • name: string

      name of element

    Returns number

  • Start iterations on all of the elements on the canvas. Sets mode to "playing", and requests a new animation frame, saving it in loopint.

    Parameters

    • Optional canvasSizes: CanvasSizes

      If mode is already "playing" then canvasSizes is passed to reset. Otherwise reset is not called.

    Returns void

  • fills the screen with value, at an optional given percent

    Parameters

    • value: string | number

      The element to put on the screen

    • Optional pr: number

      The percent as a number from 1 to 100, defaulting at 15

    Returns void

  • Reset, resize and initialize the canvas(es). Calls pause then update. Resets all internal state, excluding the element definitions.

    Parameters

    • Optional canvasSizes: CanvasSizes

      Allows one to change the size of the canvases during the reset.

    Returns void

  • Set a pixel in a given location.

    Parameters

    • loc: Location
    • ident: string | number

      Value to identify the element.

      • If a string, it assumes it's an element name.
      • If a number, it assumes it's an element ID

    Returns void

  • Parameters

    • value: number

      The new height of the canvas

    Returns void

  • Parameters

    • value: number

      The new width of the canvas

    Returns void

  • Calculate the total number of elements within an area

    Returns

    The total

    Parameters

    • area: Location[]

      The locations to total up.

    • search: string | number

      The element to look for

    Returns number

  • See

    fundamentalStatesWithin for lower-level tool

    Returns

    Number used as bit area to indicate occupied cells

    Parameters

    • current: Location

      "Current" pixel location. (Defaults loop to false)

    • search: string | number

      element to look for

    Returns number

  • Counter tool used in slower wolfram algorithim.

    Deprecated

    Replaced with wolframNearby for use in faster algorithms

    Returns

    Number of elements in wolfram radius

    Parameters

    • current: Location

      "Current" pixel location

    • name: string | number

      element to look for

    • binDex: string | number

    Returns boolean

  • See

    fundamentalNewState for more general tool.

    Returns

    The state that the bitfied says this pixel should be in the next frame.

    Parameters

    • loc: Location

      The pixel to change. (Defaults loop to false)

    • ruleNum: number

      A bitfield of what states a pixel should live or die on.

    • search: string | number

      The element to search for

    Returns boolean

Generated using TypeDoc