Skip to content

Instantly share code, notes, and snippets.

@Slikey
Last active December 29, 2019 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Slikey/cb27ae7bfd6b4a547ec070ba0953d5c9 to your computer and use it in GitHub Desktop.
Save Slikey/cb27ae7bfd6b4a547ec070ba0953d5c9 to your computer and use it in GitHub Desktop.
Some better coloring for nnoggi
-- h must be [0.0, 1.0]
-- based on [0.0, 360.0] degrees on the HSV color circle
function MDT_GetHueColor(h)
local i = math.floor(h * 6)
local f = h * 6 - i
local q = 1 - f
i = i % 6
local r, g, b
if i == 0 then r, g, b = 1, f, 0
elseif i == 1 then r, g, b = q, 1, 0
elseif i == 2 then r, g, b = 0, 1, f
elseif i == 3 then r, g, b = 0, q, 1
elseif i == 4 then r, g, b = f, 0, 1
elseif i == 5 then r, g, b = 1, 0, q
end
return r, g, b
end
function MDT_Random(seed)
return bit.band(seed * 97, 0xFF) / 0xFF
end
function MDT_GetRandomColor(seed)
return MDT_GetHueColor(MDT_Random(seed))
end
-- you want to avoid red colors so we have to limit the hue to [0.1, 0.9]
-- values around 0.0 are red
function MDT_GetRandomNonRedColor(seed)
return MDT_GetHueColor(MDT_Random(seed) * 0.8 + 0.1)
end
-- example code generating 10 random colors for different seeds
for i = 0, 10 do
print(string.format("%.2f, %.2f, %.2f", MDT_GetRandomNonRedColor(i)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment