p5.js | lerp() Function
The lerp() function is used to find a number between two numbers. The amt parameter can be used to specify the amount to interpolate between the two values. An amount nearer to 0.1 would mean that the final value is nearer to the first value, and nearer to 0.9 means that the value is nearer to the second value. If the value is less or more than these, then the final value would be calculated on the basis of the ratio of the two numbers.
It can be used for drawing dotted lines or creating motion along a path by finding all the intermediate points in a line.
lerp( start, stop, amt )
Parameters: This function accept three parameters as mentioned above and described below:
- start: It is a number which denotes the first value of the two numbers.
- stop: It is a number which denotes the second value of the two numbers..
- amt: It is a number which denotes the amount by which a number is to be interpolated between the two numbers.
Return Value: It returns a number with the lerped value.
Below examples illustrate the lerp() function in p5.js:
Online editor: https://editor.p5js.org/
Environment Setup: https://www.geeksforgeeks.org/p5-js-soundfile-object-installation-and-methods/
Please Login to comment...