konfeti - v0.6.0
    Preparing search index...

    Type Alias PhysicsDefinition<TOptions>

    Custom Physics Module Definition. Enabled per burst with physics: { <name>: true | { ...options } }; true uses defaults.

    definePhysics("magnet", {
    defaults: { x: 0.5, y: 0.5, strength: 600 },
    apply: (p, dt, world, { x, y, strength }) => {
    p.vx += (x * world.width - p.x) * strength * dt * 0.001;
    p.vy += (y * world.height - p.y) * strength * dt * 0.001;
    },
    });

    apply runs for every particle every frame — keep it allocation-free.

    type PhysicsDefinition<TOptions extends object> = {
        apply: (
            particle: MutableParticle,
            dt: number,
            world: PhysicsWorldState,
            options: Readonly<TOptions>,
        ) => void;
        defaults: Readonly<TOptions>;
        stage?: "force" | "constraint";
    }

    Type Parameters

    • TOptions extends object
    Index
    apply: (
        particle: MutableParticle,
        dt: number,
        world: PhysicsWorldState,
        options: Readonly<TOptions>,
    ) => void

    Apply Module to One Particle.

    defaults: Readonly<TOptions>

    Option Defaults (merged under the burst's options).

    stage?: "force" | "constraint"

    Pipeline Stage. "force" runs before positions update (change velocity), "constraint" after (clamp position).

    "force"