4

I have an array of color values. I have an interpolating parameter, t, which varies from 0 to 1.

I can't for the life of me figure out how to smoothly interpolate between these color values based on t, such that I get a smooth blended color for any t value.

Any ideas? Its probably something simple that I am blanking out on..

lokstok
  • 43
  • 2

1 Answers1

3

Say you have colors

$[c_1, c_2, c_3, c_4, c_5]$

And $t$ values at which each color should be purely displayed.

$[t_1, t_2, t_3, t_4, t_5]$

Now your problem is given $t$ which color do I have to display?

  1. Find the t-values $t_i$ and $t_{(i+1)}$ between which $t$ lies.
  2. Calculate a 0 to 1 ratio where $t$ lies between them

$ param = (t - t_i) / (t_{(i+1)} - t_i) $

  1. Interpolate the color via

$ c = param * c_i + (1-param) * c_{(i+1)}$

If I haven't messed up something in my mind, this should work for any piecwise linear function, and not only if your $t_i$ values lie between 0 and 1.

Dragonseel
  • 1,790
  • 1
  • 10
  • 23