WoW:USERAPI RGBToHex: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
No edit summary
 
m (Move page script moved page USERAPI RGBToHex to USERAPI RGBToHex without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:


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

Latest revision as of 04:49, 15 August 2023

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 value set (0-255) and converts it into a hex string.

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