GSDP:GAM100/CProcessing/CP Math ClampInt()
From Inside
< GSDP:GAM100 | CProcessing
CP_Math_ClampInt()
Description
Clamps an input int to an input int range and returns the clamped value.
Parameters
CP_Math_ClampInt(int value, int min, int max)
- value - (int) The value to clamp to the input range.
- min - (int) The minimum value in the range.
- max - (int) The maximum value in the range.
Example
void update(void)
{
// Get the mouse position/canvas size ratio
float mx = (float)CP_Input_GetMouseWorldX()/(float)CP_System_GetWindowWidth();
float my = (float)CP_Input_GetMouseWorldY()/(float)CP_System_GetWindowHeight();
// Convert to 0-255 values for color
int r_color = (int)(mx * 255);
int b_color = (int)(my * 255);
// Clamp the values
r_color = CP_Math_ClampInt(r_color, 0, 255);
b_color = CP_Math_ClampInt(b_color, 0, 255);
// Set the background as the color
CP_Settings_Background(CP_Color_Create(r_color, 0, b_color, 255));
}