Reference lerp()

lerp()

Calculates a number between two numbers at a specific increment.

The amt parameter is the amount to interpolate between the two numbers. 0.0 is equal to the first number, 0.1 is very near the first number, 0.5 is half-way in between, and 1.0 is equal to the second number. The lerp() function is convenient for creating motion along a straight path and for drawing dotted lines.

If the value of amt is less than 0 or more than 1, lerp() will return a number outside of the original interval. For example, calling lerp(0, 10, 1.5) will return 15.

lerp() can also be used in shaders with p5.strands, where it maps to the mix() function in GLSL. The following example uses lerp() to blend colors on a shape over time.

Examples

Syntax

lerp(start, stop, amt)

Parameters

start
Number: first value.
stop
Number: second value.
amt
Number: number.

Returns

Number: lerped value.

Related References