Invert GMLscripts.com

lerp

NOTE: The GameMaker:Studio function of the same name produces the same results and obsoletes this script.

Computes the linear interpolation between two given values.

Wikipedia: Linear interpolation is often used to fill the gaps in a table. Suppose you have a table listing the population of some country in 1970, 1980, 1990 and 2000, and that you want to estimate the population in 1994. Linear interpolation gives you an easy way to do this.

The basic operation of linear interpolation between two values is so commonly used in computer graphics that it is sometimes called a lerp in that field's jargon. The term can be used as a verb or noun for the operation. e.g. "Bresenham's algorithm lerps incrementally between the two endpoints of the line."

lerp

lerp(a,b,x)
Returns a if x is 0, b if x is 1, for other values of x returns linear interpolation of a to b controlled by x.
COPY/// lerp(a,b,x)
//
//  Returns a if x is 0, b if x is 1, for other values 
//  of x returns linear interpolation of a to b controlled by x.
//
//      a           lower value, real
//      b           upper value, real
//      x           fraction (0-1), real
//
/// GMLscripts.com/license
{
    return (argument0 + argument2 * (argument1 - argument0));
}

Contributors: xot

GitHub: View · Commits · Blame · Raw