GSDP:GAM100/CProcessing/CP ColorHSV

From Inside
Jump to: navigation, search

CP_ColorHSV

Description

CP_ColorHSV stores a color in Hue, Saturation, Value, and Alpha form. Note, you must use CP_Color_FromColorHSV() to use a CP_ColorHSV in any function that takes a CP_Color.

Color channels in HSV have different ranges than RGB.

Hue is in the range of 0 - 360

Saturation and Value are in the range of 0 - 100

Alpha is still in the range of 0 - 255

Example

void update()
{
    // Get the current framecount and set the background to black
    int frameCount = CP_System_GetFrameCount();
    CP_Settings_Background(CP_Color_Create(0, 0, 0, 255));
    
    // Use framecount to slowly change the HSV color through all colors of the rainbow
    CP_ColorHSV hsv = CP_ColorHSV_Create((frameCount * 3) % 360, 100, 50, 255);
    CP_Settings_Fill(CP_Color_FromColorHSV(hsv));
    CP_Graphics_DrawRectAdvanced(10, 10, 380, 185, 0, 20);
    
    // Do some similar color math on RBG (less convenient)
    CP_Color rgb = CP_Color_Create((int)((sinf(frameCount * 0.05f) + 1.0f) * 128.0f) % 256,
        (int)((sinf(frameCount * 0.05f + 2.0f * CP_Math_PI / 3.0f) + 1.0f) * 128.0f) % 256,
        (int)((sinf(frameCount * 0.05f + 4.0f * CP_Math_PI / 3.0f) + 1.0f) * 128.0f) % 256, 255);
    CP_Settings_Fill(rgb);
    CP_Graphics_DrawRectAdvanced(10, 205, 380, 185, 0, 20);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>