Garry's Mod Wiki

Color

  Color Color( number r, number g, number b, number a = 255 )

Description

Creates a Color.

This function is relatively expensive when used in rendering hooks or in operations requiring very frequent calls (like loops for example) due to object creation and garbage collection. It is better to store the color in a variable or to use the default colors available.

Arguments

1 number r
An integer from 0-255 describing the red value of the color.
2 number g
An integer from 0-255 describing the green value of the color.
3 number b
An integer from 0-255 describing the blue value of the color.
4 number a = 255
An integer from 0-255 describing the alpha (transparency) of the color.(default 255)

Returns

1 Color
The created Color.

Example

Creates a color and prints the components to the console.

PrintTable( Color( 1, 2, 3, 4 ) )
Output:
a = 4 b = 3 g = 2 r = 1

Example

Color variables can have individual channels set using the arguments.

local col = Color( 0, 255, 0 ) col.r = 255 PrintTable( col )
Output:
a = 255 b = 0 g = 255 r = 255

Example

Transforms a color object to a string, then prints it.

local str = tostring( Color( 255, 0, 0 ) ) print( str )
Output:
255 0 0

Example

Prints equal if both colors are equal, otherwise unequal will be printed.

if Color( 255, 0, 0 ) == Color( 255, 0, 0 ) then print( "equal" ) else print( "unequal" ) end
Output:
equal