Global/Color

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Added source code link)
(People should know this)
Line 1: Line 1:
 
{{Func
 
{{Func
 
|Description=Creates a {{Struct|Color}}.
 
|Description=Creates a {{Struct|Color}}.
 +
{{Note|This function creates a new table for the color. It's a good practice to localize your colors.}}
 
|Realm=Shared and Menu
 
|Realm=Shared and Menu
 
|IsClass=No
 
|IsClass=No

Revision as of 22:31, 11 January 2020

 Color( )

Contents

Description

Creates a Color structure.

NOTE

This function creates a new table for the color. It's a good practice to localize your colors.

Arguments

number r

An integer from 0-255 describing the red value of the color.

Arguments

number g

An integer from 0-255 describing the green value of the color.

Arguments

number b

An integer from 0-255 describing the blue value of the color.

Arguments

number a=255

An integer from 0-255 describing the alpha (transparency) of the color.

Returns

table

The created Color structure.

Examples

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

Examples

Example

Color variables can have individual channels set using the arguments

local col = Color( 0, 255, 0, 255)

col.r = 255

PrintTable(col)

Output:

a	=	255
b	=	0
g	=	255
r	=	255

Examples

Example

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

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

Output:

255 0 0

Examples

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
Personal tools
Navigation