Created
October 24, 2021 03:56
-
-
Save demonnic/bf50cd8c80a0d96766478143251561b2 to your computer and use it in GitHub Desktop.
getAlertGradientTable(max): Create a table of r,g,b color values for an alert scale 1 - max
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function getBadnessLevel(num, max) | |
local halfWay = (max+1) / 2 | |
local stepSize = 255 / (halfWay - 1) | |
local r,g,b = 0,255,0 | |
if num <= 1 then | |
return r,g,b | |
end | |
if num > max then | |
return 255,0,0 | |
end | |
if num < halfWay then | |
r = math.floor((num - 1) * stepSize) | |
return r,g,b | |
else | |
r = 255 | |
g = 255 - math.floor((num - halfWay) * stepSize) | |
return r,g,b | |
end | |
end | |
function getAlertGradientTable(max) | |
local result = {} | |
for i = 1, max do | |
result[i] = {getBadnessLevel(i, max)} | |
end | |
return result | |
end | |
--[[ | |
-- code below this creates a Mudlet demonstration of what the colors look like on a 1-10 scale. | |
echo("\n\n") | |
local grads = getAlertGradientTable(10) | |
for lvl, clr in ipairs(grads) do | |
local r,g,b = unpack(clr) | |
local txt = f"<{r},{g},{b}>Badness level is {lvl}\n" | |
decho(txt) | |
end | |
--]] |
Author
demonnic
commented
Oct 24, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment