The lerpColor() function is used to interpolate two colors to find a third color between them. The amount of interpolation between the two colors can be set using the amt parameters. The color interpolation depends on the current color mode.
lerpColor(c1, c2, amt)
Parameters: This function accepts three parameters as mentioned above and described below:
- c1: It is a p5.Color which represents the first color from which the final color will be interpolated.
- c2: It is a p5.Color which represents the second color to which the final color will be interpolated.
- amt: It is a number between 0 and 1 which determines which color will be used more for the interpolation. A value near 0.1 would prefer the first color more and a value near 0.9 would prefer the second color for interpolation.
Return Value: It returns a p5.Color element with the interpolated color.
The example below illustrate the lerpColor() function in p5.js:
Online editor: https://editor.p5js.org/