GSDP:GAM100/CProcessing/CP ColorHSV Lerp()

From Inside
Jump to: navigation, search

CP_ColorHSV_Lerp()

Description

Linearly interpolate (lerp) between two given CP_ColorHSV 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_ColorHSV_Lerp(CP_ColorHSV a, CP_ColorHSV b, float lerp_factor)

  • a - (CP_ColorHSV) the base color to lerp from. The return value is a when lerp_factor = 0.0
  • b - (CP_ColorHSV) 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 left and right side of the screen
    CP_ColorHSV start = CP_ColorHSV_Create(0, 100, 50, 255);
    CP_ColorHSV end = CP_ColorHSV_Create(359, 100, 50, 255);
    
    // Get the mouse position relative to the canvas
    float mx = (float)CP_Input_GetMouseWorldX() / (float)CP_System_GetCanvasWidth();
    
    // Clamp the values
    mx = CP_Math_ClampFloat(mx, 0.0f, 1.0f);
    
    // Lerp the colors based on mouse position along the x-axis
    CP_ColorHSV lerp = CP_ColorHSV_Lerp(start, end, mx);
    
    // Set the background based on the lerp
    CP_Settings_Background(CP_Color_FromColorHSV(lerp));
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>