RGB2Hex

Share your scripts and packages with other Mudlet users.
Post Reply
JerleMinara
Posts: 7
Joined: Sat Dec 05, 2009 12:56 am

RGB2Hex

Post by JerleMinara »

This will be implemented in 1.0.5 or 1.1.0 whichever comes first

Code: Select all

-- Converts an RGB value into an HTML compliant(label usable) HEX number
-- Example: RGB2Hex(255,255,255) returns "FFFFFF"
function RGB2Hex(red,green,blue)
									
	return PadHexNum(string.format("%X",red)) .. 
			PadHexNum(string.format("%X",green)) .. 
			PadHexNum(string.format("%X",blue))
end

-- Pads a hex number to ensure a minimum of 2 digits.
-- Example: PadHexNum("F") returns "F0
function PadHexNum(incString)
	local l_Return = incString
	if tonumber(incString,16)<16 then
		if tonumber(incString,16)<10 then
			l_Return = "0" .. l_Return
		elseif tonumber(incString,16)>10 then
			l_Return = l_Return .. "0"
		end
	end

	return l_Return
end

Post Reply