GSDP:GAM100/CProcessing/CP Color Lerp()
From Inside
< GSDP:GAM100 | CProcessing
CP_Color_Lerp()
Description
Linearly interpolate (lerp) between two given CP_Color inputs using an interpolation factor from 0.0 to 1.0. Returns the newly computed color.
The calculation applied to each component of the color:
new_color = (1.0f - lerp_factor) * a + lerp_factor * b;
Parameters
CP_Color_Lerp(CP_Color a, CP_Color b, float lerp_factor)
- a - (CP_Color) the base color to lerp from. The return value is a when lerp_factor = 0.0
- b - (CP_Color) the end color to lerp to. The return values is b when lerp_factor = 1.0
- lerp_factor - (float) the value between 0.0 and 1.0 used to linearly interpolate from a to b
Example
void update()
{
// Create colors for the four corners of the screen
CP_Color red = CP_Color_Create(255, 0, 0, 255);
CP_Color green = CP_Color_Create(0, 255, 0, 255);
CP_Color blue = CP_Color_Create(0, 0, 255, 255);
CP_Color white = CP_Color_Create(255, 255, 255, 255);
// Get the mouse position relative to the canvas
float mx = (float)CP_Input_GetMouseWorldX() / (float)CP_System_GetCanvasWidth();
float my = (float)CP_Input_GetMouseWorldY() / (float)CP_System_GetCanvasHeight();
// Clamp the values
mx = CP_Math_ClampFloat(mx, 0.0f, 1.0f);
my = CP_Math_ClampFloat(my, 0.0f, 1.0f);
// Lerp the colors based on position along the x-axis
CP_Color lerpx1 = CP_Color_Lerp(red, blue, mx);
CP_Color lerpx2 = CP_Color_Lerp(green, white, mx);
// Lerp the two previous colors based on y-axis position
CP_Color lerp = CP_Color_Lerp(lerpx1, lerpx2, my);
// Set the background based on the lerp
CP_Settings_Background(lerp);
}
Related
- Main Page
- CP_Color
- CP_ColorHSV
- CP_Color_Create()
- CP_ColorHSV_Create()
- CP_Color_Lerp()
- CP_ColorHSV_Lerp()
- CP_Color_FromColorHSV()
- CP_ColorHSV_FromColor()
- CP_Settings_Background()
- CP_Input_GetMouseWorldX()
- CP_Input_GetMouseWorldY()
- CP_System_GetCanvasWidth()
- CP_System_GetCanvasHeight()
- CP_Math_ClampFloat()