ixfx
    Preparing search index...

    Function apply

    • Apply a series of force functions or forces to t. Null/undefined entries are skipped silently. It also updates the velocity and position of the returned version of t.

      // Wind adds acceleration. Force is dampened by mass
      const wind = Forces.accelerationForce({ x: 0.00001, y: 0 }, `dampen`);

      // Gravity adds acceleration. Force is magnified by mass
      const gravity = Forces.accelerationForce({ x: 0, y: 0.0001 }, `multiply`);

      // Friction is calculated based on velocity. Force is magnified by mass
      const friction = Forces.velocityForce(0.00001, `multiply`);

      // Flip movement velocity if we hit a wall. And dampen it by 10%
      const bouncer = Forces.constrainBounce({ width: 1, height: 1 }, 0.9);

      let t = {
      position: Points.random(),
      mass: 0.1
      };

      // Apply list of forces, returning a new version of the thing
      t = Forces.apply(t,
      gravity,
      wind,
      friction,
      bouncer
      );

      Parameters

      Returns ForceAffected