utils.color
Methods36
function Color.new(...: any) -> Color
Create a new Color object. it can be passed, A Color, a string color name, an array, a list of float paramaters (RGB), a color dictionary, or hex
function Color.__call(...: any) -> Color
function Color.load(color: Color) -> Color
Loads the color metatmethods into table without any checking.
function Color.copy(color: Color, alpha: float | nil) -> Color
Copies the color into a new Color.
colorColoralphafloat | nil[opt] Change the alpha of the copied color
- Color
function Color.white() -> Color
Returns a white Color.
function Color.black() -> Color
Returns a black color.
function Color.from_string(string_name: string, alpha: float | nil) -> Color
Returns a color from a string name if known. Returns white if color string is unknown
string_namestringalphafloat | nil[opt]
- Color
function Color.from_params(r: float | nil, g: float | nil, b: float | nil, a: float | nil) -> Color
Converts a color in the rgb format to a color table.
rfloat | nil[opt=0] 0-255 red
gfloat | nil[opt=0] 0-255 green
bfloat | nil[opt=0] 0-255 blue
afloat | nil[opt=255] 0-255 alpha
- Color
function Color.from_rgb(r: float | nil, g: float | nil, b: float | nil, a: float | nil) -> Color
rfloat | nil[opt=0] 0-255 red
gfloat | nil[opt=0] 0-255 green
bfloat | nil[opt=0] 0-255 blue
afloat | nil[opt=255] 0-255 alpha
- Color
Color.from_params
function Color.from_array(color: float[], alpha: float | nil) -> Color
Converts a color in the array format to a color in the table format.
colorfloat[]the color to convert — { [1] = @{float}, [2] = @{float}, [3] = @{float}, [4] = @{float} }
alphafloat | nil[opt]
- Color
a converted color — { r = c_arr[1], g = c_arr[2], b = c_arr[3], a = c_arr[4] }
function Color.from_table(color: table, alpha: float | nil) -> Color
Converts a color in the dictionary format to a color in the Color format.
colortablethe color to convert
alphafloat | nil[opt]
- Color
function Color.from_hex(color: string, alpha: float[opt]) -> a Color
Get a color table with a hexadecimal string. Optionally provide the value for the alpha channel.
colorstringhexadecimal color string (#ffffff, not #fff)
alphafloat[opt]
aColorcolor table with RGB converted from Hex and with alpha
function Color.set(color, alpha) -> any
Deprecated
function Color.normalize(color: Color) -> Color
Normalizes a color between 0 and 1
function Color.alpha(color: Color, alpha: float | nil) -> Color
Set the alpha channel on a color
colorColoralphafloat | nil[opt = 1]
- Color
function Color.premul_alpha(color: Color, alpha: float) -> nil
Premultiply alpha
function Color.add(lhs: Color, rhs: Color) -> nil
Add 2 colors together.
function Color.subtract(lhs: Color, rhs: Color) -> nil
Subtract 2 colors together.
function Color.multiply(lhs: Color, rhs: Color) -> nil
Multiply 2 colors together.
function Color.divide(lhs: Color, rhs: Color) -> nil
Add 2 colors together.
function Color.modulo(lhs: Color, rhs: Color) -> Color
Modulo of 2 colors.
function Color.unary(color: Color) -> Color
Flip a color to white or black.
function Color.len(color: Color) -> number
Get the length of a color by adding all its values together
function Color.equals(lhs: Color, rhs: Color) -> boolean
Are both colors equal.
function Color.less_than(lhs: Color, rhs: Color) -> boolean
Is LHS less than RHS.
function Color.less_than_eq(lhs: Color, rhs: Color) -> boolean
Is LHS less than or equal to RHS.
function Color.to_hex(color: Color) -> string
Return a hex formated string from a color.
function Color.to_array(color: Color) -> table
Return an array with 4 paramaters.
function Color.pack(color: Color) -> table
Color.to_array
function Color.to_params(color: Color) -> ...unknown
Return the color as 4 paramaters.
function Color.unpack(color: Color) -> ...unknown
Color.to_params
function Color.to_string(color: Color) -> string
Return the Color as a string.
function Color.is_complex(color: Color) -> boolean
Is this a correctly formatted color.
function Color.is_Color(color: Color) -> boolean
Is this a Color object.
function Color.is_color(color: Color) -> boolean
Is this a Color object or correctly formatted color table.
function Color.best_color_match(color) -> nil
Takes a color and table of colors, finds key of color in table that most closely matches given color
Fields5
Color.__class: string = "Color"
Color.__index : unknown
Color.color : unknown
@table color @{defines.color}
Color.anticolor : unknown
@table anticolor @{defines.anticolor}
Color.lightcolor : unknown
@table lightcolor @{defines.lightcolor}