Reference lerp()

lerp()

Calculates new vector components that are proportionally the same distance between two vectors.

lerp() can use separate numbers, as in v.lerp(3, 3, 0.5), another p5.Vector object, as in v.lerp(v2, 0.5), or an array of numbers, as in v.lerp([3, 3], 0.5). When using numbers, the last argument is always the interpolation amount.

The amt parameter is the amount to interpolate between the old vector and the new vector. 0.0 keeps all components equal to the old vector's, 0.5 is halfway between, and 1.0 sets all components equal to the new vector's. Values of amt outside the range 0 to 1 are allowed and extrapolate beyond the target.

This method supports N-dimensional vectors. You should interpolate vectors only when they are the same size. When two vectors of different sizes are used, the smaller dimension will be used, and any additional values of the longer vector will be ignored.

The static version of lerp(), as in p5.Vector.lerp(v0, v1, 0.5), returns a new p5.Vector object and doesn't change the originals.

Examples

Syntax

lerp(args1, args2, ..., argsn)
lerp(arr, amt)
lerp(v, amt)

Parameters

args1, ..., argsn
Number: target vector components followed by the interpolation amount. The last argument is always amt (0.0 keeps the old vector, 1.0 the new vector, 0.5 is halfway between).
arr
Number[]: array to lerp towards.
amt
Number:
v
p5.Vector: p5.Vector to lerp toward.

Related References