Name

lerpColor()

Description

Calculates a color between two colors at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 is equal to the first point, 0.1 is very near the first point, 0.5 is halfway in between, etc.
An amount below 0 will be treated as 0. Likewise, amounts above 1 will be capped at 1. This is different from the behavior of lerp(), but necessary because otherwise numbers outside the range will produce strange and unexpected colors.

Examples

  • 
    size(400,400);
    background(51);
    stroke(255);
    color from = color(204, 102, 0);
    color to = color(0, 102, 153);
    color interA = lerpColor(from, to, .33);
    color interB = lerpColor(from, to, .66);
    fill(from);
    rect(40, 80, 80, 240);
    fill(interA);
    rect(120, 80, 80, 240);
    fill(interB);
    rect(200, 80, 80, 240);
    fill(to);
    rect(280, 80, 80, 240);
    Image output for example 1

Syntax

  • lerpColor(c1, c2, amt)

Parameters

  • c1(int)interpolate from this color
  • c2(int)interpolate to this color
  • amt(float)between 0.0 and 1.0

Return

  • int