• Performs linear interpolation (lerp) between two numbers based on a blending factor.

    Parameters

    • start: number

      The starting value.

    • end: number

      The ending value.

    • alpha: number

      The blending factor, clamped to the range [0, 1].

    Returns number

    The result of linear interpolation between start and end using alpha.

    // Interpolate between two values.
    const value1 = 10;
    const value2 = 20;
    const alpha = 0.5; // Blend halfway between value1 and value2.
    const result = lerp(value1, value2, alpha);
    // result is 15

    // Ensure alpha is clamped to the range [0, 1].
    const value3 = 5;
    const value4 = 15;
    const invalidAlpha = 1.5; // This will be clamped to 1.
    const result2 = lerp(value3, value4, invalidAlpha);
    // result2 is 15, equivalent to lerp(value3, value4, 1)
""