Class Sempiternal

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

Hierarchy (view full)

Constructors

Properties

alternateSpin: boolean

If true: every other ring will rotate in the opposite direction.

backgroundColour: null | string

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

Default: null

circleSize: number

The radius (px) of each circle.

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

delay: number

A value between 0 and 1 indicating what percentage behind in the loop each successive ring will be.

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

opacityPulse: HexPulse

Controls the pulse in opacity (see HexPulse)

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)}

parentDraw: (() => void) = ...

Type declaration

    • (): void
    • Uses this.context to draw the current frame of the animation, as determined by this.currProgress. Called by this.animate.

      Returns void

parentSetConfig: ((ops: Partial<SempiternalOps>) => void) = ...

Type declaration

    • (ops): void
    • Sets one or more configurable properties of this Animautomaton.

      Parameters

      • ops: Partial<SempiternalOps>

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

      Returns void

radiusPulse: HexPulse

Controls the pulse in opacity (see HexPulse)

relativeExpansion: number

The number of circle radii each 'ring' is from the origin.

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

rotations: number

Number of rotations to complete in one loop. Must be an integer.

sideLength: number

The number of circles per side of the hexagon, also the number of 'rings'.

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

  • 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

  • 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.

  • Adjusts this.context's opacity based on the current opacityPulse settings.

    Parameters

    • level: number

      The ring of the shape.

    Returns void

  • Calculates the circle radius for a given level with the current radius pulse settings.

    Parameters

    • level: number

    Returns number

    The effective radius for this level given current progress.

  • 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