WoW:USERAPI RGBPercToHex: Difference between revisions

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


Takes a RGB percent set (0.0-1.0) and converts it to a hex string.
Takes a RGB percent set (0.0-1.0) and converts it to a hex string.
 
<pre>
  local function RGBPercToHex(r, g, b)
  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)
  return string.format("%02x%02x%02x", r*255, g*255, b*255)
  end
  end
</pre>

Latest revision as of 04:49, 15 August 2023

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 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