diff --git a/suppfunc.lua b/suppfunc.lua new file mode 100644 index 0000000..efcc5c5 --- /dev/null +++ b/suppfunc.lua @@ -0,0 +1,34 @@ + + +-- Converts HEXRGB to RGB +function hexrgb(hashtag) + hashtag = string.lower(hashtag) + local r1 = hex_to_dec(hashtag:sub(2,2)) + local r2 = hex_to_dec(hashtag:sub(3,3)) + local g1 = hex_to_dec(hashtag:sub(4,4)) + local g2 = hex_to_dec(hashtag:sub(5,5)) + local b1 = hex_to_dec(hashtag:sub(6,6)) + local b2 = hex_to_dec(hashtag:sub(7,7)) + + return (r1*16 + r2)/255, (g1*16 + g2)/255, (b1*16 + b2)/255 +end + +function hex_to_dec(hex) + if hex == "0" then return 0 + elseif hex == "1" then return 1 + elseif hex == "2" then return 2 + elseif hex == "3" then return 3 + elseif hex == "4" then return 4 + elseif hex == "5" then return 5 + elseif hex == "6" then return 6 + elseif hex == "7" then return 7 + elseif hex == "8" then return 8 + elseif hex == "9" then return 9 + elseif hex == "a" then return 10 + elseif hex == "b" then return 11 + elseif hex == "c" then return 12 + elseif hex == "d" then return 13 + elseif hex == "e" then return 14 + elseif hex == "f" then return 15 + end +end \ No newline at end of file