GSDP:GAM100/CProcessing/CP Math LerpInt()

From Inside
Jump to: navigation, search

CP_Math_LerpInt()

Description

Linearly interpolates between two input integers with an input lerp factor.

Parameters

CP_Math_LerpInt(int a, int b, float lerp_factor)

  • a - (int) The value the function returns when lerp_factor is 0.0, the starting value.
  • b - (int) The value the function returns when lerp_factor is 1.0, the ending value.
  • lerp_factor - (float) The ratio used to determine what value to return between a and b.

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 = CP_Math_LerpInt(0, 255, mx);
  int b_color = CP_Math_LerpInt(0, 255, my);

  // 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));
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>