Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:USERAPI ColorGradient
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{userfunc}} __NOTOC__ Converts a percent value into a gradient from 2 or more RGB percent values (0.0-1.0). If more than 2 colors are passed, the gradient will be between the two colors which perc lies in an evenly divided range. (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.) local function ColorGradient(perc, ...) if perc >= 1 then local r, g, b = select(select('#', ...) - 2, ...) return r, g, b elseif perc <= 0 then local r, g, b = ... return r, g, b end local num = select('#', ...) / 3 local segment, relperc = math.modf(perc*(num-1)) local r1, g1, b1, r2, g2, b2 = select((segment*3)+1, ...) return r1 + (r2-r1)*relperc, g1 + (g2-g1)*relperc, b1 + (b2-b1)*relperc end == 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. 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
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Notebox
(
edit
)
Template:Userfunc
(
edit
)