Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local hexadecimal, rgb, hex, index
- local pairs, tonumber = pairs, tonumber
- local string_len, math_fmod, math_floor = string.len, math.fmod, math.floor
- local list = {}
- for i = 1, string_len("0123456789ABCDEF") do
- list[i - 1] = string.sub("0123456789ABCDEF", i, i)
- end
- local Color_Cache = {}
- return function(r, g, b)
- rgb = {r, g, b}
- if Color_Cache[rgb] then
- return Color_Cache[rgb]
- end
- hexadecimal = "0x"
- for _, value in ipairs(rgb) do
- hex = ""
- while value > 0 do
- index = math_fmod(value, 16)
- value = math_floor(value / 16)
- hex = list[index] .. hex
- end
- if string_len(hex) == 0 then
- hex = "00"
- elseif string_len(hex) == 1 then
- hex = "0".. hex
- end
- hexadecimal = hexadecimal .. hex
- end
- Color_Cache[rgb] = tonumber(hexadecimal)
- return Color_Cache[rgb]
- end
Add Comment
Please, Sign In to add comment