WoW:USERAPI RGBPercToHex: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
m (Imp RGBPercToHex)
No edit summary
Line 5: Line 5:


  local function RGBPercToHex(r, g, b)
  local function RGBPercToHex(r, g, b)
    if r > 1 or r < 0 then
r = r <= 1 and r >= 0 and r or 0
        r = 0
g = g <= 1 and g >= 0 and g or 0
    end
b = b <= 1 and b >= 0 and b or 0
    if g > 1 or g < 0 then
return string.format("%02x%02x%02x", r*255, g*255, b*255)
        g = 0
    end
    if b > 1 or b < 0 then
        b = 0
    end
    return string.format("%02x%02x%02x", r*255, g*255, b*255)
  end
  end

Revision as of 22:11, 30 September 2007

This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions


Takes a RGB percent set (0.0-1.0) and converts it to a hex string.

local function RGBPercToHex(r, g, b)
	r = r <= 1 and r >= 0 and r or 0
	g = g <= 1 and g >= 0 and g or 0
	b = b <= 1 and b >= 0 and b or 0
	return string.format("%02x%02x%02x", r*255, g*255, b*255)
end