Function interpolatorStepped

Returns a function that interpolates from A to B. It steps through the interpolation with each call to the returned function. This means that the incrementAmount will hinge on the rate at which the function is called. Alternatively, consider interpolatorInterval which steps on the basis of clock time.

// Interpolate from 0..1 by 0.01
const v = interpolatorStepped(0.01, 100, 200);
v(); // Each call returns a value closer to target
// Eg: 100, 110, 120, 130 ...

Under the hood, it calls interpolate with an amount that increases by incrementAmount each time.

When calling v() to step the interpolator, you can also pass in new B and A values. Note that the order is swapped: the B (target) is provided first, and then optionally A.

const v = interpolatorStepped(0.1, 100, 200); // Interpolate 100->200
v(300, 200); // Retarget to 200->300 and return result
v(150); // Retarget 200->150 and return result

This allows you to maintain the current interpolation progress.

  • Parameters

    • incrementAmount: number

      Amount to increment by

    • a: number = 0

      Start value. Default: 0

    • b: number = 1

      End value. Default: 1

    • startInterpolationAt: number = 0

      Starting interpolation amount. Default: 0

    • Optionaloptions: Partial<InterpolateOptions>

      Options for interpolation

    Returns ((retargetB?: number, retargetA?: number) => number)

      • (retargetB?, retargetA?): number
      • Parameters

        • OptionalretargetB: number
        • OptionalretargetA: number

        Returns number