Class AnimautomatonAbstract

Abstract parent class containing shared properties and methods for all animautomatons.

Hierarchy (view full)

Constructors

Properties

backgroundColour: null | string

If not null: the canvas will be painted this colour.

Default: null

colours: string[]

An array of 7-character hex code colour strings (e.g. ["#ffffff"]). (Must be 7 characters for opacity to work properly.)

currIteration: number

The current iteration of this animation.

Default: 0

currProgress: number

A number between 0 and 1 representing the animation's progress through its loop THIS frame.

Default: 0

customTimingFunction: ((offset?: number) => number)

This function will be called iff timingFunction = "custom"

Custom timing functions must take in an offset to apply to currProgress, and return a value between 0 and 1.

cycleDuration_ms: number

Number of milliseconds this animation's loop will take. Lower = faster.

Default: 1000

drawStyle: "fill" | "stroke"

Represents which Context2D drawing function to call.

Default: fill

fps: number

Number of requested renders per second (not guaranteed!).

Default: 60

lastMutationTimestamp: number

High resolution timestamp (ms) of when this animation was last mutated.

Default: 0

lastProgress: number

A number between 0 and 1 representing the animation's progress through its loop LAST frame.

Default: 0

nIterations: number

This animation will pause after this many loops.

Default: Infinity (i.e. animation continues forever)

opacity: number

A number between 0 and 1.

The base transparcency to apply to colours when drawing.

Default: 1

opacityDelta: number

Each differentiable section will have this much less opacity than the previous section (minimum 0).

Default: 0

origin: Vector2

The (x,y) value of the geometric centre of the canvas.

Default: {x: Math.floor(canvas.width / 2), y: Math.floor(canvas.height / 2)}

rest: number

A number between 0 and 1.

This animation will be still in its starting position for this proportion of its duration.

Default: 0

timingFunction:
    | "linear"
    | "sinusoidal"
    | "quadratic"
    | "cubic"
    | "custom"

Transformation to apply to this animation's progress.

Default: sinusoidal

Methods

  • This function is called every animation frame & decides whether or not to draw a new frame of this animation, and also whether or not to call mutate().

    Returns void

  • Given two points {from} and {to}, calculates the control points necessary to draw a Bezier curve from {from} to {to} that is part of a circle with center of {originOffset}

    Parameters

    Returns BezierControlPoints

    An object containing the Bezier control points.

  • Draws a circular bezier curve from the start position to the end position with the center point of originOffset.

    Parameters

    Returns void

  • Draws the current path in this.context based on this.drawStyle.

    Returns void

  • Draws a line from the current position of this.context to the position given by vector v.

    Parameters

    Returns void

  • Sets new opacity to: currentOpacity + currentOpacity * modifier. Enforces minimum of 0.

    Parameters

    • modifier: number

    Returns void

  • Sets both context.strokeStyle and context.fillStyle with appropriate opacity.

    Parameters

    • offset: number

      The index of the colour in this.colours (wraps around).

    Returns void

  • Parent draw() must be called at the start of childrens' draw() methods.

    Returns void

  • Draws a radius 2 circle at the position given. Used for debugging.

    Parameters

    Returns void

  • Parameters

    • Optionaloffset: number

      An amount to either add or subtract from the base progress before transformation.

    Returns number

    A value between 0 and 1 representing the animation's progress through its loop, transformed according to this.timingFunction.

  • Parameters

    • pow: number
    • Optionaloffset: number

    Returns number

  • Parameters

    • Optionaloffset: number

    Returns number

  • Parameters

    • Optionaloffset: number

    Returns number

  • This function must be called at the end of all child class constructors.

    Returns void

  • Moves the animation immediately a certain number of frames.

    Parameters

    • frames: number

      Number of frames to seek (negative = rewind, 0 = re-render current frame)

    Returns void

  • Sets one or more configurable properties of this Animautomaton.

    Parameters

    • ops: Partial<AnimautomatonOps>

      An object containing one or more valid {AnimautomatonOps} properties.

    Returns void