WoW:USERAPI ColorGradient: Difference between revisions

no edit summary
m (Move page script moved page USERAPI ColorGradient to WoW:USERAPI ColorGradient without leaving a redirect)
No edit summary
 
Line 5: Line 5:


(Note that if you will always be generating a gradient between the same number of colors, you will see *significantly* greater performance if you customize this function to take a fixed number of arguments.)
(Note that if you will always be generating a gradient between the same number of colors, you will see *significantly* greater performance if you customize this function to take a fixed number of arguments.)
 
<pre>
  local function ColorGradient(perc, ...)
  local function ColorGradient(perc, ...)
  if perc >= 1 then
  if perc >= 1 then
Line 22: Line 22:
  return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
  return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc
  end
  end
</pre>


== Example ==
== Example ==
For this example we'll use 3 colors: red, yellow and green.  For a percent value of 0.75 we'd expect to get back a color that's halfway between yellow and green.  0.5 would yield pure yellow, 0.25 would yield an orange.
For this example we'll use 3 colors: red, yellow and green.  For a percent value of 0.75 we'd expect to get back a color that's halfway between yellow and green.  0.5 would yield pure yellow, 0.25 would yield an orange.
 
<pre>
  local r,g,b = ColorGradient(0.75, 1,0,0, 1,1,0, 0,1,0)
  local r,g,b = ColorGradient(0.75, 1,0,0, 1,1,0, 0,1,0)
  -- r = 0.5, g = 1.0, b = 0.0
  -- r = 0.5, g = 1.0, b = 0.0
</pre>