Garry's Mod Wiki

Color

Color

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

Description

Creates a Color.

This function is very expensive when used in rendering hooks or in operations requiring very frequent calls (like loops for example). 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.

Returns

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

Special Pages


Wikis

?

Render Time: 59ms

DB GetPage 34
Generate Html 8
SaveChanges (1) 6
Render Body 0
Render Sidebar 9