How do I cycle/lerp between multiple colors

For a quick, off-the-shelf multicolor extension to lerpColor, define a function lerpColors:

color lerpColors(float amt, color... colors) {
  if(colors.length==1){ return colors[0]; }
  float cunit = 1.0/(colors.length-1);
  return lerpColor(colors[floor(amt / cunit)], colors[ceil(amt / cunit)], amt%cunit/cunit);
}

Examples of how to use this function:

Many past discussions:

4 Likes