GSDP:GAM100/CProcessing/clampInt()

From Inside
Jump to: navigation, search

clampInt()

Description

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

Parameters

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)worldMouseX/(float)canvasWidth;
  float my = (float)worldMouseY/(float)canvasHeight;

  // Convert to 0-255 values for color
  int r_color = (int)(mx * 255);
  int b_color = (int)(my * 255);

  // Clamp the values
  r_color = clampInt(r_color, 0, 255);
  b_color = clampInt(b_color, 0, 255);

  // Set the background as the color
  background(color(r_color, 0, b_color, 255));
}

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>