ixfx
    Preparing search index...
    • For a given set of attractors, returns a function that a sets acceleration of attractee. Keep note though that this bakes-in the values of the attractor, it won't reflect changes to their state. For dynamic attractors, it might be easier to use computeAttractionForce.

      Type Parameters

      Parameters

      • attractors: readonly ForceAffected[]

        Things that will attract other things. They must have a position and mass

      • gravity: number

        Gravity constant. This will have to be tweaked to taste. A value of 0.005 is a good starting point

      • distanceRange: { max?: number; min?: number } = {}

        Min/max that distance is clamped to. This affects how tightly the particles will orbit and can also determine speed. By default it is 0.001-0.7

        • Optional Readonlymax?: number

          Maximum distance. Defaults to 0.7

        • Optional Readonlymin?: number

          Minimum distance. Defaults to 0.001

      Returns (attractee: T) => T

      A function that can be applied to a thing to set its acceleration based on the attractors

      const f = Forces.attractionForce(sun, gravity);
      earth = Forces.apply(earth, f);
      // Create a force with all things as attractors.
      const f = Forces.attractionForce(things, gravity);
      // Apply force to all things.
      // The function returned by attractionForce will automatically ignore self-attraction
      things = things.map(a => Forces.apply(a, f));