GSDP:GAM100/CProcessing/CP Color

From Inside
Jump to: navigation, search

CP_Color

Description

CP_Color is a type that stores color values in red, green and blue components (RGB). The function CP_Color_Create() can be used to create a color and you can also access the individual color values directly or as an array.

Each color channel is represented by a number between 0 and 255. Where 0 is no color and 255 is full color for that channel. Some example colors:

black - CP_Color_Create(0, 0, 0, 255)

white - CP_Color_Create(255, 255, 255, 255)

gray 50% - CP_Color_Create(128, 128, 128, 255)

red - CP_Color_Create(255, 0, 0, 255)

green - CP_Color_Create(0, 255, 0, 255)

blue - CP_Color_Create(0, 0, 255, 255)

Example

void update() 
{
    // Use the CP_Color_Create function with the values of our background color
    CP_Color color1 = CP_Color_Create(255, 40, 100, 255);
    
    // Set the background with color1 (berry red)
    CP_Settings_Background(color1);
    
    // Create a second color and access its values individually
    CP_Color color2;;
    color2.r = 0;	// Red
    color2.g = 200;	// Green
    color2.b = 255;	// Blue
    color2.a = 255;	// Alpha (transparency)
    
    // Set the fill color for shapes with color2
    CP_Settings_Fill(color2);
    
    // Draw a rectangle at the top left of the screen (blue)
    float rectWidth = CP_System_GetCanvasWidth() * 0.7f;
    float rectHeight = CP_System_GetCanvasHeight() * 0.7f;
    CP_Graphics_DrawRect(0, 0, rectWidth, rectHeight);
    
    // Create a third CP_Color and set the values by accessing the array
    CP_Color color3;
    color3.rgba[0] = 150;	// Red
    color3.rgba[1] = 255;	// Green
    color3.rgba[2] = 40;	// Blue
    color3.rgba[3] = 255;	// Alpha (transparency)
    
    // Set the fill color for the final shape
    CP_Settings_Fill(color3);
    
    // Draw another smaller rectange (green)
    rectWidth = CP_System_GetCanvasWidth() * 0.4f;
    rectHeight = CP_System_GetCanvasHeight() * 0.4f;
    CP_Graphics_DrawRect(0, 0, rectWidth, rectHeight);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>