GSDP:GAM100/CProcessing/lerpColor()
From Inside
< GSDP:GAM100 | CProcessing
lerpColor()
Description
Linearly lerps between 2 given color values on a scale from 0.0 to 1.0. Returns the newly determined color.
Parameters
lerpColor(PColor a, PColor b, float t)
- a - (PColor) the base color to lerp from. The return value is a when t = 0.0
- b - (PColor) the end color to lerp to. The return values is b when t = 1.0
- t - (float) the value between 0.0 and 1.0 used to linearly lerp from a to b
Example
static PColor Red;
static PColor Green;
static PColor Blue;
static PColor White;
void init()
{
// 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()
{
// 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
backgroundColor(lerp);
}