WoW:USERAPI RGBToHex: Difference between revisions

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


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

Revision as of 13:36, 30 September 2007

This page documents a user-defined function 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 value set (0-255) and converts it into a hex string.

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