Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

Color

A color represented in RGBA format.

Description

A color represented in RGBA format by a red (r), green (g), blue (b), and alpha (a) component. Each component is a 32-bit floating-point value, usually ranging from 0.0 to 1.0. Some properties (such as CanvasItem.modulate) may support values greater than 1.0, for overbright or HDR (High Dynamic Range) colors.

Colors can be created in various ways: By the various Color constructors, by static methods such as from_hsv, and by using a name from the set of standardized colors based on X11 color names with the addition of TRANSPARENT. GDScript also provides @GDScript.Color8, which uses integers from 0 to 255 and doesn't support overbright colors.

Note: In a boolean context, a Color will evaluate to false if it is equal to Color(0, 0, 0, 1) (opaque black). Otherwise, a Color will always evaluate to true.

Color constants cheatsheet

Note

There are notable differences when using this API with C#. See C# API differences to GDScript for more information.

Tutorials

Properties

float

a

1.0

int

a8

255

float

b

0.0

int

b8

0

float

g

0.0

int

g8

0

float

h

0.0

float

r

0.0

int

r8

0

float

s

0.0

float

v

0.0

Constructors

Color

Color ( )

Color

Color ( Color from, float alpha )

Color

Color ( Color from )

Color

Color ( String code )

Color

Color ( String code, float alpha )

Color

Color ( float r, float g, float b )

Color

Color ( float r, float g, float b, float a )

Methods

Color

blend ( Color over ) const

Color

clamp ( Color min=Color(0, 0, 0, 0), Color max=Color(1, 1, 1, 1) ) const

Color

darkened ( float amount ) const

Color

from_hsv ( float h, float s, float v, float alpha=1.0 ) static

Color

from_ok_hsl ( float h, float s, float l, float alpha=1.0 ) static

Color

from_rgbe9995 ( int rgbe ) static

Color

from_string ( String str, Color default ) static

float

get_luminance ( ) const

Color

hex ( int hex ) static

Color

hex64 ( int hex ) static

Color

html ( String rgba ) static

bool

html_is_valid ( String color ) static

Color

inverted ( ) const

bool

is_equal_approx ( Color to ) const

Color

lerp ( Color to, float weight ) const

Color

lightened ( float amount ) const

Color

linear_to_srgb ( ) const

Color

srgb_to_linear ( ) const

int

to_abgr32 ( ) const

int

to_abgr64 ( ) const

int

to_argb32 ( ) const

int

to_argb64 ( ) const

String

to_html ( bool with_alpha=true ) const

int

to_rgba32 ( ) const

int

to_rgba64 ( ) const

Operators

bool

operator != ( Color right )

Color

operator * ( Color right )

Color

operator * ( float right )

Color

operator * ( int right )

Color

operator + ( Color right )

Color

operator - ( Color right )

Color

operator / ( Color right )

Color

operator / ( float right )

Color

operator / ( int right )

bool