Map with LerpColor

Use Map and LerpColor to define Color Gradients across a Region

Given 2 colors c1, c2, use the map function to calculate how a fraction value changes across a region. The calculated fraction is used in LerpColor to create a new color: curColor. See full code below for extended version using similar logic.

  color c1 = color( 230, 100, 100); //purple 
  color c2 = color( 80, 100, 100); //lime
  
  //define curColor based on mX relative to balancePoint 
  float fraction = map( mX, 0, width, 0.0, 1.0); 
  
  color curColor = lerpColor( c2, c1, fraction); //fraction varies beteween 0.0, 1.0
  
 

Last updated

Was this helpful?