konfeti - v0.6.0
    Preparing search index...

    Function definePhysics

    • Register Custom Physics Module. Declare its options on PhysicsRegistry first; enable it per burst with physics: { name: … }. Registering the same name again replaces the definition.

      Type Parameters

      • K extends never

      Parameters

      Returns void

      TypeError for built-in keys

      declare module "konfeti" {
      interface PhysicsRegistry {
      magnet: { x: number; y: number; strength: number };
      }
      }

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

      Konfeti.fire({ physics: { magnet: { strength: 900 } } });