Physics-Banner Library API - v1.0.0
    Preparing search index...

    Class default

    Rigid body physics simulation for ascii art/text. Uses opentype.js to get character paths from a font. Supports gravity, collisions, boundary behavior, and optional debugging.

    Index
    • Creates a banner on the given canvas and begins observing its size and visibility. Call setup before spawning text to load the font.

      Parameters

      • canvas: HTMLCanvasElement

        Canvas on which the banner is rendered.

      • font_url: string

        URL of the font used to create the character, supports only WOFF/OTF/TTF type font and not WOFF2.

      • color: string = 'black'

        Color used when initializing the character cache.

      • font_size: number = 36

        Font size used to build character polygons.

      • segmenter: string = 'en'

        Locale used to split text into grapheme clusters.

      Returns default

      If a 2D rendering context cannot be obtained.

    • Safely destroys this class by stoping the physics loop and releases the event listeners and observers. Automatically called when this class is disposed.

      Returns void

    • Parameters

      • bounds: boolean

        true makes the entities bounce at the edges; false makes them loop at edges.

      Returns void

    • Parameters

      • debug: boolean

        Whether debug rendering should be enabled.

      Returns void

    • Starts the physics loop if it is not already running.

      Returns void

    • Parameters

      • gravity: number

        Gravity acceleration; zero to disable gravity.

      Returns void

    • Parameters

      • random_speed: number

        Magnitude of the initial shooting velocity.

      Returns void

    • Parameters

      • characters: string

        Characters that are picked randomly to be shot at.

      Returns void

    • Loads the configured font into the character polygon cache.

      Returns Promise<void>

    • Fires a random character inward from the screen.

      Returns void

    • Spawns a single character at a position with the given velocity.

      Parameters

      • x: number

        Initial horizontal center position.

      • y: number

        Initial vertical center position.

      • char: string

        Character to spawn.

      • velX: number

        Initial horizontal velocity.

      • velY: number

        Initial vertical velocity.

      Returns void

    • Spawns the characters into the physics world.

      Parameters

      • characters: string

        Text to spawn.

      • HPostion: number = .5

        Horizontal placement from 0 (left) to 1 (right) and 0.5 is the center.

      • VPosition: number = .5

        Vertical placement from 0 (top) to 1 (bottom) and 0.5 is the center.

      • textAlignment: "left" | "center" | "right" = "left"

        Alignment of each line within the text block. Text is lined up along the left, center, right margin.

      Returns void

    • Stops the physics loop while leaving the banner ready to resume.

      Returns void