Performs linear interpolation between two values.
The mix() function linearly interpolates between two values based on a third parameter. It's a GLSL built-in function available in p5.strands shaders.
The function computes: x * (1 - a) + y * a
When a is 0.0, the function returns x. When a is 1.0, it returns y. Values between 0.0 and 1.0 produce a linear blend between the two values.
This function works with scalars, vectors (vec2, vec3, vec4), and can also accept a boolean for the third parameter to select between the two values.
Note: This function is only available inside shader code created with buildMaterialShader(), buildColorShader(), or similar functions. For regular p5.js code, use lerp() instead.
Examples
Syntax
mix(x, y, a)
Parameters
x
Number|p5.Vector: first value to interpolate from.
y
Number|p5.Vector: second value to interpolate to.
a
Number|Boolean: interpolation amount (0.0-1.0) or boolean selector.
Returns
Number|p5.Vector: interpolated value.
Notice any errors or typos? Please let us know. Please feel free to edit src/strands/p5.strands.js and open a pull request!