ixfx
    Preparing search index...

    Function wrapRange

    • Performs a calculation within a wrapping number range. This is a lower-level function. See also: wrapInteger for simple wrapping within a range.

      min and max define the start and end of the valid range, inclusive. Eg for hue degrees it'd be 0, 360. a and b is the range you want to work in.

      For example, let's say you want to get the middle point between a hue of 30 and a hue of 330 (ie warmer colours):

      wrapRange(0,360, (distance) => {
      // for a:0 and b:330, distance would be 90 from 30 degrees to 330 (via zero)
      return distance * 0.5; // eg return middle point
      }, 30, 330);

      The return value of the callback should be in the range of 0-distance. wrapRange will subsequently conform it to the min and max range before it's returned to the caller.

      Parameters

      • min: number

        Range start (eg 0)

      • max: number

        Range end (eg 360)

      • fn: (distance: number) => number

        Returns a computed value from 0 to distance.

      • a: number

        Output start (eg. 60)

      • b: number

        Output end (eg 300)

      Returns number