GSDP:GAM100/CProcessing/clampFloat()

From Inside
Jump to: navigation, search

clampFloat()

Description

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

Parameters

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 PColor Red;
static PColor Green;
static PColor Blue;
static PColor White;

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

void update(void)
{
  // Get the mouse position
  float mx = (float)worldMouseX/(float)canvasWidth;
  float my = (float)worldMouseY/(float)canvasHeight;

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

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

  // Lerp them together
  PColor lerp = lerpColor(lerpx, lerpy, 0.5f);

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

Related

Personal tools
Namespaces

Variants
Actions
Navigation
NameSpaces:>
Tools
Dynamic:>