Open main menu
Home
Random
Donate
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Value color
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!
local getArgs = require('Module:Arguments').getArgs local p = {} local function rgb(color) local _, _, R, G, B = color:find('(%w%w)(%w%w)(%w%w)') return tonumber(R, 16), tonumber(G, 16), tonumber(B, 16) end function p.main(frame) local args = getArgs(frame) local value = tonumber(args[1]) local minValue = tonumber(args[2]) local maxValue = tonumber(args[3]) if value == nil or minValue == nil or maxValue == nil then return require('Module:Error').error{'Parameters 1, 2, and 3 are required and must be numbers.'} end local minR, minG, minB = rgb(args[4] or 'FFFFFF') local maxR, maxG, maxB = rgb(args[5] or '000000') local percent = math.max(0, math.min(1, (value - minValue) / (maxValue - minValue))) local red = minR + ((maxR - minR) * percent) local green = minG + ((maxG - minG) * percent) local blue = minB + ((maxB - minB) * percent) if args['hex'] then return string.format('#%x%x%x', red, green, blue) else return string.format('rgb(%.0f,%.0f,%.0f)', red, green, blue) end end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Value color/doc
(
edit
)