promotional bannermobile promotional banner
premium banner
A library to easy coloring strings by hex codes, color tables, class names, color names and more.

Description

Short description

A library to easy coloring strings by hex codes, color tables, class names, color names and more.

 

Supported types

  • Hex code with 8 and 6 characters. [<alpha>]<red><green><blue> like 9E342C (alpha is optional)
  • Color table in two variants: { <red[number]>, <green[number]>, <blue[number]>, <alpha[number](optional)> } or { ["r"] = <{ <red[number]>, ["g"] = <green[number]>, ["b"] = <blue[number]>, ["a"] = <alpha[number](optional)> }
  • Class names supports english and localized names on non english clients
  • ITEM_QUALITY_COLORS as quality[number] and lower string version of ITEM_QUALITY[number]_DESC
  • or keywords
    • playerclass will be relaced with the current players class color
  • Cecond parameter must not be a string to coloring it
    • not set second parameter returns hex color code
    • the string "colortable" as second parameter returns the requested color as color table

To use in addons

lib = LibStub("LibColors-1.0")
 

API

num2hex

Convert a number between 0 and 1 into a hex code between 00 and ff

 string = lib:num2hex( number ) 

 

colorTable2HexCode

Converts numeric or associative color tables into a 8 character long hex color code.

assoc_table = { r = 0.8, g = 0.8, b = 0.1, a = 1 }
	numeric_table = {
		0.8, -- red
		0.8, -- green
		0.8, -- blue
		1 -- alpha
	}
	string = lib:colorTable2HexCode( table )

Any not defined or nil table entry will be ignored. An empty table returns the hex code for the color white.

 

hexCode2ColorTable

converts a hex code into a color table

 table = lib:hexCode2ColorTable( string ) 	
 

colorset

Add a single color code to list of known colors

 lib:colorset( string, string or table ) 

or add a list of color codes

table = { ["color name"] = color string or color table }lib:colorset( table ) 
 

color

Create a colored string like |c<color><string>|r

 string = lib:color( color, string )

As first parameter you can use colors names, color tables or keywords. Currently implemented keyword for colors are "playerclass".
As second parameter you can use normal text or a keyword. Currently implemented keyword for second parameter are "colortable" that returns the requested color as colortable.

 

getNames

The parameter are optional and used to return matching color names.

 table = lib:getNames( [string] )
 

colorGradient (new)

Creates a color between 2 or 3 colors selected by an fraction (float) value between 0 and 1.

 colorTable = lib:gradientColor( fraction, colorTable1, colorTable2[, colorTable3] )
 hexColorCode = lib:gradientColor( fraction, hexColorCode1, hexColorCode2[, hexColorCode3] )

Arguments:

  1. fraction (number) - float number between 0 and 1
  2. color1 (table|string) - Color table {<red(number)>, <green(number)><blue(number)>} or hex color code RRGGBB. 
  3. color2 (table|string) - Same like color1. Must not be the same type as color1.
  4. color3 (table|string) - optional -- Same like color2. Must not be the same type as color1.
 

Return:

  • table|string - color table or hex color code; depends on argument color1 if table or string
 

Available colors

Direct integrated

colors = {
	-- basic colors
	yellow = "ffff00",
	orange = "ff8000",
	red    = "ff0000",
	violet = "ff00ff",
	blue   = "0000ff",
	cyan   = "00ffff",
	green  = "00ff00",
	black  = "000000",
	gray   = "808080",
	white  = "ffffff",
	-- wow money colors
	money_gold   = "ffd700",
	money_silver = "eeeeef",
	money_copper = "f0a55f",
}

Color sets in extra files

You can find 3 files named colors_<name>.lua in the directory and in LibColors-1.0.xml the lines to use it. The sources for the color sets are on top of the files.

 

Licence

To the hell with all licenses, the hole money, all weapons and other bad things... :P

 

Hizuro's other projects

 • https://www.curseforge.com/members/hizuro_de/projects