Skip to content

lerp

Smoothly transitions between two values based on a factor

54 bytes

Usage

The lerp function is used to linearly interpolate between two numbers based on a specified amount. This function is particularly useful in animations, graphics, and games for smooth transitions.

import * as _ from 'radashi'
_.lerp(0, 10, 0.5) // => 5
_.lerp(5, 15, 0.2) // => 7
_.lerp(-10, 10, 0.75) // => 5

Etymology

The name lerp is short for “linear interpolation”. It’s a term from computer graphics that means “interpolate linearly between two values”.

For more information, check out the Wikipedia article on linear interpolation.