Built-in functions: math_mix()
The function math_mix() performs a linear interpolation between two values according to a specified weight.
Declaration
Form 1:
int32 math_mix( int32 aValue1, int32 aValue2, float aFactor )
uint32 math_mix( uint32 aValue1, uint32 aValue2, float aFactor )
int64 math_mix( int64 aValue1, int64 aValue2, float aFactor )
uint64 math_mix( uint64 aValue1, uint64 aValue2, float aFactor )
float math_mix( float aValue1, float aValue2, float aFactor )
Form 2:
point math_mix( point aValue1, point aValue2, float aFactor )
rect math_mix( rect aValue1, rect aValue2, float aFactor )
color math_mix( color aValue1, color aValue2, float aFactor )
Parameters
aValue1
The start of the range in which to perform the interpolation.
aValue2
The end of the range in which to perform the interpolation.
aFactor
The weight to control the interpolation between aValue1 and aValue2.
Discussion
The function math_mix() performs a linear interpolation between the values aValue1 and aValue2 according to a specified weight aFactor. The return value is calculated as aValue1 * ( 1.0 - aFactor ) + aValue2 * aFactor. If aFactor is less than 0.0, the function returns aValue1. If aFactor is greater than 1.0, the function returns aValue2. In its first form the function limits to calculate with operands containing single numbers only. For example:
var float mix1 = math_mix( 1.0, 5.7, 0.4 ); // mix1 = 2.88 var float mix2 = math_mix( 1.0, 5.7, -0.5 ); // mix2 = 1.0 var float mix3 = math_mix( 1.0, 5.7, +1.5 ); // mix3 = 5.7 var int32 mix4 = math_mix( -1251, 1369, 0.3 ); // mix4 = 466
The second form accepts parameters of more complex data types containing multiple components each. For example, an operand of type point contains the components x and y. In this case the function performs the interpolation component-wise. Similarly, with color operands, the function calculates the resulting values for the red, green, blue and alpha color components separately. For example:
var point mix1 = math_mix( <1,8>, <5,2>, 0.4 ); // mix1 = <2,6> var color mix2 = math_mix( #12345678, #AA121122, 0.4 ); // mix2 = #4E263A55