A cellular automata engine

Type Parameters

  • T

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 renderers.Renderer.defaultRenderAs in PixelManipulator.renderer

elements: ElementData<T>[] = []

A low-level listing of the availiable elements.

Format is much like the argument to PixelManipulator.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) = ...

Called after PixelManipulator.iterate does its work.

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

Gets called after a call to PixelManipulator.modifyElement. The ID is passed as the only argument.

Type declaration

    • (id): void
    • Parameters

      • id: number

        The element that was modified.

      Returns void

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

Called before PixelManipulator.iterate does its work.

Type declaration

    • (): boolean | void
    • Returns boolean | void

      false to postposne iteration.

pixelCounts: Record<number, number> = {}

Number of pixels per element in the last frame

renderer: Renderer<T>

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

Methods

  • Parameters

    • loc: Location

      Where to confirm the element

    • id: string | number

      The elm you expect it to be

    Returns boolean

    Does the cell at loc match ident?

  • Parameters

    • area: Location[]

      Locations to look at.

    • search: string | number

      Locations to mark as a true bit.

    Returns number

    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.

    PixelManipulator.fundamentalNewState for higher-level tool

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

    Be careful! Calling this while PixelManipulator.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

  • Parameters

    • loc: Location

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

    Returns null | Location

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

  • Parameters

    • center: Location

      location of the center of the moore area

    • search: string | number

    Returns number

    Number of matching elements in moore radius

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

    Parameters

    • name: string

      name of element

    Returns number

    The number of the element

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

    Parameters

    • value: string | number

      The element to put on the screen

    • Optionalpr: number

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

    Returns void

  • Parameters

    • value: number

      The new height of the canvas

    Returns void

  • Parameters

    • value: number

      The new width of the canvas

    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

  • Calculate the total number of elements within an area

    Parameters

    • area: Location[]

      The locations to total up.

    • search: string | number

      The element to look for

    Returns number

    The total

  • Counter tool used in slower wolfram algorithim.

    Parameters

    • current: Location

      "Current" pixel location

    • name: string | number

      element to look for

    • binDex: string | number

    Returns boolean

    Number of elements in wolfram radius

    Replaced with PixelManipulator.wolframNearby for use in faster algorithms