static Color Lerp( Color& a, Color& b, float frac, bool clamped )

book_4_sparkGenerated
code_blocksInput

Description

The Color.Lerp method performs a linear interpolation between two colors, a and b, based on a given fraction frac. The interpolation can be clamped to ensure the resulting color components remain within the valid range of 0 to 1.

Usage

Use this method when you need to blend two colors smoothly. The frac parameter determines the weight of each color in the interpolation, where 0 results in color a and 1 results in color b. If clamped is set to true, the resulting color components will be clamped to the range [0, 1].

Example

Color colorA = new Color(1.0f, 0.0f, 0.0f, 1.0f); // Red
Color colorB = new Color(0.0f, 0.0f, 1.0f, 1.0f); // Blue
float fraction = 0.5f;
bool clamp = true;

Color resultColor = Color.Lerp(ref colorA, ref colorB, fraction, clamp);
// resultColor will be a blend of red and blue, resulting in purple if clamped.