GSDP:GAM100/CProcessing/CP Math ClampFloat()

From Inside
Jump to: navigation, search

CP_Math_ClampFloat()

Description

Clamps an input float to an input float range and returns the clamped value.

Parameters

CP_Math_ClampFloat(float value, float min, float max)

  • value - (float) The value to clamp to the input range.
  • min - (float) The minimum value in the range.
  • max - (float) The maximum value in the range.

Example

static CP_Color Red;
static CP_Color Green;
static CP_Color Blue;
static CP_Color White;

void init(void)
{
  // Create colors for the four corners of the screen
  Red = CP_Color_Create(255, 0, 0, 255);
  Green = CP_Color_Create(0, 255, 0, 255);
  Blue = CP_Color_Create(0, 0, 255, 255);
  White = CP_Color_Create(255, 255, 255, 255);
}

void update(void)
{
  // Get the mouse position
  float mx = (float)CP_Input_GetMouseWorldX()/(float)CP_System_GetWindowWidth();
  float my = (float)CP_Input_GetMouseWorldY()/(float)CP_System_GetWindowHeight();

  // Clamp the values
  mx = CP_Math_ClampFloat(mx, 0.0, 1.0);
  my = CP_Math_ClampFloat(my, 0.0, 1.0);

  // Lerp along both axis
  CP_Color lerpx = CP_Color_Lerp(Red, Blue, mx);
  CP_Color lerpy = CP_Color_Lerp(Green, White, my);

  // Lerp them together
  CP_Color lerp = CP_Color_Lerp(lerpx, lerpy, 0.5f);

  // Set the background based on the lerp
  CP_Settings_Background(lerp);
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>