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

    Physics-Banner Library API - v1.0.0

    Physics-Banner

    A rigid body physics simulation for ascii art, build using typescript and HTMLcanvas element. It uses one dependecy opentype.js for geting paths from a font.

    npm install @nickolasddiaz/physics-banner
    
    import PhysicsBanner from "@nickolasddiaz/physics-banner";

    physics_banner = new PhysicsBanner(yourHTMLCanvasElement, font_url(WOFF/OTF/TTF type font and not WOFF2), "black", font_size);
    await physics_banner.setup();

    const ascii_art = ... // multi-line string
    physics_banner.spawn_string(ascii_art);
    .
    ├── index.html # HTML for the demo
    └── src # Mono-repo for libary and demo
    ├── ascii_art.txt # Text file for the ascii art
    ├── demo.ts # Demo code using tweakpane
    └── lib # Libary implementation
    ├── PhysicsObject
    │   ├── PhysicsObject.ts # Class to manage the character body, handles updating and drawing characters
    │   └── checkCollision.ts # Function to handle the SAT collision detection and response of the PhysicsObject.ts
    ├── collision
    │   ├── quadtree.ts # Used to efficiently query for PhysicsObjects and perform a bounding box test
    │   └── rectangle.ts # Helper class for quadtree.ts to split quadrants
    ├── font
    │   └── PolygonCache.ts # Stores convex hull polygon points using from opentype.js libary, offscreencanvas for drawing, and width/height for each character
    ├── geometry
    │   ├── point.ts # Extends vec2.ts to add an instance of PhysicsObject.ts used for the quadtree.ts
    │   └── vec2.ts # Class to represent a vector 2 with common operations
    └── index.ts # Exported class for the libary
    %%{init:{"theme":"dark"}}%% graph TD; A[PhysicsObject.ts/index.ts] <--> |Gets polygon points from characters| B[PolygonCache.ts using opentype.js]; A --> C[Update Loop/requestAnimationFrame] C --> D[Clear and Insert every entity into quadtree.ts] D --> E[Query and perform AABB bounding box] E --> |AABB Hit| F[compute axes of entity A&B in checkCollision.ts] F --> G[Check if all axes overlap: SAT detection] G --> |Entities are colliding| H[Calculate and Apply MTV, angular velocity and velocity] H --> C E --> |AABB miss| C G --> |Entities are not colliding| C
    %%{init:{"theme":"default"}}%% graph TD; A[PhysicsObject.ts/index.ts] <--> |Gets polygon points from characters| B[PolygonCache.ts using opentype.js]; A --> C[Update Loop/requestAnimationFrame] C --> D[Clear and Insert every entity into quadtree.ts] D --> E[Query and perform AABB bounding box] E --> |AABB Hit| F[compute axes of entity A&B in checkCollision.ts] F --> G[Check if all axes overlap: SAT detection] G --> |Entities are colliding| H[Calculate and Apply MTV, angular velocity and velocity] H --> C E --> |AABB miss| C G --> |Entities are not colliding| C
    graph TD;
        A[PhysicsObject.ts/index.ts] <--> |Gets polygon points from characters| B[PolygonCache.ts using opentype.js];
        A --> C[Update Loop/requestAnimationFrame]
        C --> D[Clear and Insert every entity into quadtree.ts]
        D --> E[Query and perform AABB bounding box]
        E --> |AABB Hit| F[compute axes of entity A&B in checkCollision.ts]
        F --> G[Check if all axes overlap: SAT detection]
        G --> |Entities are colliding| H[Calculate and Apply MTV, angular velocity and velocity]
        H --> C
        E --> |AABB miss| C
        G --> |Entities are not colliding| C

    Adapted from the coding train, quadtree.js

    Adapted from danielszabo88, 15 - Separating Axis Theorem and dyn4j article )

    Adapted from danielszabo88, 16 - Minimum Translation Vector

    Adapted from danielszabo88, 14 - Rotational Collision and Dr. Nicolas Pronost

    Adapted from geeksforgeeks, Convex Hull using Graham Scan

    1. Git clone the respository

      git clone https://github.com/nickolasddiaz/Physics-Banner.git && cd Physics-Banner
      
    2. Development Server

      npm run dev
      
    3. Build the libary

      npm run build:lib
      
    4. Build the docs and demo

      npm run build:demo
      
    5. Preview the demo

      npm run preview