Function lerp

  • Performs linear interpolation (LERP) between a current value and a target value using an easing factor.

    Linear interpolation calculates an intermediate value between current and target based on a given factor, providing smooth transitions.

    Parameters

    • current: number

      The starting value.

    • target: number

      The end value.

    • factor: number

      The interpolation factor, typically between 0 and 1. A lower value results in slower interpolation, while a higher value makes it faster.

    • Optionalapproximation: number = 0

      A small threshold to determine when the difference between the interpolated value and the target is negligible. If the difference is within this threshold, the function returns target directly.

    Returns number

    • The interpolated value.
    lerp(0, 1, 0.4);
    // => 0.4 (40% progress from 0 to 1)

    lerp(0.75, 0.8, 0.98);
    // => 0.799 (close to the target but not exactly 0.8)

    lerp(0.75, 0.8, 0.98, 0.01);
    // => 0.8 (within the approximation threshold)