Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- DOCUMENTATION:
- All types of HEX Converter on ROBLOX in one place.
- --]]
- local function GetRGBFromData(Color)
- return {(Color.R * 255), (Color.G * 255), (Color.B * 255)} -- {(Color.R), (Color.G), (Color.B)}
- end
- local function InvertHexColor(Hex)
- Hex = string.upper(Hex)
- Hex = string.sub(Hex, 2)
- local InvertedHex = "#" -- "0x"
- for Index = 0, 2 do
- local Component = string.sub(Hex, (1 + Index * 2), (2 + Index * 2) )
- Component = tonumber("0x" .. Component)
- Component = (0xff - Component)
- InvertedHex = (InvertedHex .. string.format("%.2x", Component) )
- end
- return string.upper(InvertedHex)
- end
- local function ConvertRGBToHex(RGB)
- local Hexadecimal = "#" -- "0x"
- for _, Value in pairs(RGB) do
- local Hex = ""
- while Value > 0 do
- local Index = (math.fmod(Value, 16) + 1)
- Value = math.floor(Value / 16)
- Hex = (string.sub("0123456789ABCDEF", Index, 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
- return Hexadecimal
- end
- local function ConvertHexToRGB(Hex)
- Hex = Hex:gsub("#", "") -- Hex:gsub("0x", "")
- local R = (tonumber("0x" .. Hex:sub(1, 2) ) * 255) -- tonumber("0x" .. Hex:sub(1, 2) )
- local G = (tonumber("0x" .. Hex:sub(3, 4) ) * 255) -- tonumber("0x" .. Hex:sub(1, 2) )
- local B = (tonumber("0x" .. Hex:sub(5, 6) ) * 255) -- tonumber("0x" .. Hex:sub(1, 2) )
- return R, G, B
- end
- print( ConvertRGBToHex({255, 255, 255}) ) -- Output: #FFFFFF
- print( Color3.fromRGB(ConvertHexToRGB("#FFFFFF") ) ) -- Output: 255, 255, 255
- print( InvertHexColor("#FFFFFF") ) -- Output: #000000
- print( Color3.fromRGB(ConvertHexToRGB(InvertHexColor("#FFFFFF") ) ) ) -- Output: 0, 0, 0
- print( ConvertRGBToHex(GetRGBFromData(workspace.Baseplate.Color) ) ) -- Output: #635F62
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement