Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Saved color codes, saving codes in here
- -- in case they are needed another time.
- local savedColors = {};
- local HEX_BASE = 16; -- 0 - F = 16.
- -- Hex digits (10 - 15) and a check function.
- local hexDigits = {'A', 'B', 'C', 'D', 'E', 'F'};
- local function isHexDigit(hexStr)
- for _, v in ipairs(hexDigits) do
- if v == hexStr then return true end;
- end
- return false;
- end
- -- Function to convert a decimal number to
- -- a hexadecimal number.
- local function decToHex(dec)
- local hex = "";
- while dec ~= 0 do
- local temp = dec % HEX_BASE
- if temp >= 10 then
- temp = hexDigits[temp-9];
- end
- hex = temp .. hex;
- dec = math.floor(dec / HEX_BASE);
- end
- if isHexDigit(hex) or tonumber(hex) and tonumber(hex) < 10 then
- hex = "0" .. hex;
- elseif hex == "" then
- hex = "00";
- end
- return hex;
- end
- -- Function to create the color code usable
- -- in WoW.
- local function createColorCode(...)
- local colorCode = "";
- local colorTable = {select(1, ...)};
- for _, v in ipairs(colorTable) do
- if tonumber(v) == nil then
- return false;
- end
- colorCode = colorCode .. decToHex(v);
- end
- return "|cff" .. colorCode;
- end
- -- This is the function to call to get the color
- -- code associated with the RGB code.
- -- RGB is a representation of a color mix of three
- -- colors: R (red), G (green) and B (blue).
- -- Numbers vary between 0 and 255.
- -- Examples:
- -- 255, 0, 0 = red. Only red is used, so obv. we get red.
- -- 150, 0, 0 = dark red. Only red is used, however slightly,
- -- so we get a darker color.
- -- 0, 255, 0 = green.
- -- 255, 0, 255 = purple. A mix of red and blue = purple.
- function RGB(red, green, blue)
- local key = red .. green .. blue;
- local color = savedColors[key];
- if color == nil then
- color = createColorCode(red, green, blue);
- savedColors[key] = color;
- end
- return color;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement