class-description NEWS COMMUNITY STORE LABS SIGN UP LOGIN LOGOUT ROKOJORI NEWSLETTER SIGN UP LOGIN LOGOUT NEWS COMMUNITY STORE LABS TOGGLE FULLSCREEN VOLLBILD AN/AUS Color
A color represented in RGBA format.

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.

Color constants cheatsheet

Color Color<>():Color

Constructs a default Color from opaque black. This is the same as BLACK.

Note: in C#, constructs an empty color with all of its components set to 0.0 (transparent black).

Color Color<>( Color from=, from:Color=, float alpha=, alpha:float=, ):Color

Constructs a Color from the existing color, with a set to the given alpha value.

var red = Color(Color.RED, 0.2) # 20% opaque red.
Color Color<>( Color from=, from:Color=, ):Color

Constructs a Color as a copy of the given Color.

Color Color<>( String code=, code:String=, ):Color

Constructs a Color either from an HTML color code or from a standardized color name. The supported color names are the same as the constants.

Color Color<>( String code=, code:String=, float alpha=, alpha:float=, ):Color

Constructs a Color either from an HTML color code or from a standardized color name, with alpha on the range of 0.0 to 1.0. The supported color names are the same as the constants.

Color Color<>( float r=, r:float=, float g=, g:float=, float b=, b:float=, ):Color

Constructs a Color from RGB values, typically between 0.0 and 1.0. a is set to 1.0.

var color = Color(0.2, 1.0, 0.7) # Similar to `Color8(51, 255, 178, 255)`
Color Color<>( float r=, r:float=, float g=, g:float=, float b=, b:float=, float a=, a:float=, ):Color

Constructs a Color from RGBA values, typically between 0.0 and 1.0.

var color = Color(0.2, 1.0, 0.7, 0.8) # Similar to `Color8(51, 255, 178, 204)`
bool operator !=<>( Color right=, right:Color=, ):bool

Returns true if the colors are not exactly equal.

Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.

Color operator *<>( Color right=, right:Color=, ):Color

Multiplies each component of the Color by the components of the given Color.

Color operator *<>( float right=, right:float=, ):Color

Multiplies each component of the Color by the given float.

Color operator *<>( int right=, right:int=, ):Color

Multiplies each component of the Color by the given int.

Color operator +<>( Color right=, right:Color=, ):Color

Adds each component of the Color with the components of the given Color.

Color operator -<>( Color right=, right:Color=, ):Color

Subtracts each component of the Color by the components of the given Color.

Color operator /<>( Color right=, right:Color=, ):Color

Divides each component of the Color by the components of the given Color.

Color operator /<>( float right=, right:float=, ):Color

Divides each component of the Color by the given float.

Color operator /<>( int right=, right:int=, ):Color

Divides each component of the Color by the given int.

bool operator ==<>( Color right=, right:Color=, ):bool

Returns true if the colors are exactly equal.

Note: Due to floating-point precision errors, consider using is_equal_approx instead, which is more reliable.

float operator []<>( int index=, index:int=, ):float

Access color components using their index. [0] is equivalent to r, [1] is equivalent to g, [2] is equivalent to b, and [3] is equivalent to a.

Color operator unary+<>():Color

Returns the same value as if the + was not there. Unary + does nothing, but sometimes it can make your code more readable.

Color operator unary-<>():Color

Inverts the given color. This is equivalent to Color.WHITE - c or Color(1 - c.r, 1 - c.g, 1 - c.b, 1 - c.a). Unlike with inverted, the a component is inverted, too.

float a<>():float

The color's alpha component, typically on the range of 0 to 1. A value of 0 means that the color is fully transparent. A value of 1 means that the color is fully opaque.

int a8<>():int

Wrapper for a that uses the range 0 to 255, instead of 0 to 1.

float b<>():float

The color's blue component, typically on the range of 0 to 1.

int b8<>():int

Wrapper for b that uses the range 0 to 255, instead of 0 to 1.

float g<>():float

The color's green component, typically on the range of 0 to 1.

int g8<>():int

Wrapper for g that uses the range 0 to 255, instead of 0 to 1.

float h<>():float

The HSV hue of this color, on the range 0 to 1.

float r<>():float

The color's red component, typically on the range of 0 to 1.

int r8<>():int

Wrapper for r that uses the range 0 to 255, instead of 0 to 1.

float s<>():float

The HSV saturation of this color, on the range 0 to 1.

float v<>():float

The HSV value (brightness) of this color, on the range 0 to 1.

Color blend<>( Color over=, over:Color=, ):Color

Returns a new color resulting from overlaying this color over the given color. In a painting program, you can imagine it as the over color painted over this color (including alpha).

var bg = Color(0.0, 1.0, 0.0, 0.5) # Green with alpha of 50% var fg = Color(1.0, 0.0, 0.0, 0.5) # Red with alpha of 50% var blended_color = bg.blend(fg) # Brown with alpha of 75%
Color clamp<>( Color=, Color:=, 0=, 0:=, 0=, 0:=, 0 )=, ):0=, Color=, Color:=, 1=, 1:=, 1=, 1:=, 1 )=, ):1=, ):Color

Returns a new color with all components clamped between the components of min and max, by running @GlobalScope.clamp on each component.

Color darkened<>( float amount=, amount:float=, ):Color

Returns a new color resulting from making this color darker by the specified amount (ratio from 0.0 to 1.0). See also lightened.

var green = Color(0.0, 1.0, 0.0) var darkgreen = green.darkened(0.2) # 20% darker than regular green
Color from_hsv<>( float h=, h:float=, float s=, s:float=, float v=, v:float=, float alpha=1.0, alpha:float=1.0, ):Color

Constructs a color from an HSV profile. The hue (h), saturation (s), and value (v) are typically between 0.0 and 1.0.

var color = Color.from_hsv(0.58, 0.5, 0.79, 0.8)
Color from_ok_hsl<>( float h=, h:float=, float s=, s:float=, float l=, l:float=, float alpha=1.0, alpha:float=1.0, ):Color

Constructs a color from an OK HSL profile. The hue (h), saturation (s), and lightness (l) are typically between 0.0 and 1.0.

var color = Color.from_ok_hsl(0.58, 0.5, 0.79, 0.8)
Color from_rgbe9995<>( int rgbe=, rgbe:int=, ):Color

Decodes a Color from a RGBE9995 format integer. See Image.FORMAT_RGBE9995.

Color from_string<>( String str=, str:String=, Color default=, default:Color=, ):Color

Creates a Color from the given string, which can be either an HTML color code or a named color (case-insensitive). Returns default if the color cannot be inferred from the string.

float get_luminance<>():float

Returns the light intensity of the color, as a value between 0.0 and 1.0 (inclusive). This is useful when determining light or dark color. Colors with a luminance smaller than 0.5 can be generally considered dark.

Note: get_luminance relies on the color being in the linear color space to return an accurate relative luminance value. If the color is in the sRGB color space, use srgb_to_linear to convert it to the linear color space first.

Color hex<>( int hex=, hex:int=, ):Color

Returns the Color associated with the provided hex integer in 32-bit RGBA format (8 bits per channel).

In GDScript and C#, the int is best visualized with hexadecimal notation ("0x" prefix, making it "0xRRGGBBAA").

var red = Color.hex(0xff0000ff) var dark_cyan = Color.hex(0x008b8bff) var my_color = Color.hex(0xbbefd2a4)
Color hex64<>( int hex=, hex:int=, ):Color

Returns the Color associated with the provided hex integer in 64-bit RGBA format (16 bits per channel).

In GDScript and C#, the int is best visualized with hexadecimal notation ("0x" prefix, making it "0xRRRRGGGGBBBBAAAA").

Color html<>( String rgba=, rgba:String=, ):Color

Returns a new color from rgba, an HTML hexadecimal color string. rgba is not case-sensitive, and may be prefixed by a hash sign (#).

rgba must be a valid three-digit or six-digit hexadecimal color string, and may contain an alpha channel value. If rgba does not contain an alpha channel value, an alpha channel value of 1.0 is applied. If rgba is invalid, returns an empty color.

var blue = Color.html("#0000ff") # blue is Color(0.0, 0.0, 1.0, 1.0) var green = Color.html("#0F0") # green is Color(0.0, 1.0, 0.0, 1.0) var col = Color.html("663399cc") # col is Color(0.4, 0.2, 0.6, 0.8)
bool html_is_valid<>( String color=, color:String=, ):bool

Returns true if color is a valid HTML hexadecimal color string. The string must be a hexadecimal value (case-insensitive) of either 3, 4, 6 or 8 digits, and may be prefixed by a hash sign (#). This method is identical to String.is_valid_html_color.

Color.html_is_valid("#55aaFF") # Returns true Color.html_is_valid("#55AAFF20") # Returns true Color.html_is_valid("55AAFF") # Returns true Color.html_is_valid("#F2C") # Returns true Color.html_is_valid("#AABBC") # Returns false Color.html_is_valid("#55aaFF5") # Returns false
Color inverted<>():Color

Returns the color with its r, g, and b components inverted ((1 - r, 1 - g, 1 - b, a)).

var black = Color.WHITE.inverted() var color = Color(0.3, 0.4, 0.9) var inverted_color = color.inverted() # Equivalent to `Color(0.7, 0.6, 0.1)`
bool is_equal_approx<>( Color to=, to:Color=, ):bool

Returns true if this color and to are approximately equal, by running @GlobalScope.is_equal_approx on each component.

Color lerp<>( Color to=, to:Color=, float weight=, weight:float=, ):Color

Returns the linear interpolation between this color's components and to's components. The interpolation factor weight should be between 0.0 and 1.0 (inclusive). See also @GlobalScope.lerp.

var red = Color(1.0, 0.0, 0.0) var aqua = Color(0.0, 1.0, 0.8) red.lerp(aqua, 0.2) # Returns Color(0.8, 0.2, 0.16) red.lerp(aqua, 0.5) # Returns Color(0.5, 0.5, 0.4) red.lerp(aqua, 1.0) # Returns Color(0.0, 1.0, 0.8)
Color lightened<>( float amount=, amount:float=, ):Color

Returns a new color resulting from making this color lighter by the specified amount, which should be a ratio from 0.0 to 1.0. See also darkened.

var green = Color(0.0, 1.0, 0.0) var light_green = green.lightened(0.2) # 20% lighter than regular green
Color linear_to_srgb<>():Color

Returns the color converted to the sRGB color space. This method assumes the original color is in the linear color space. See also srgb_to_linear which performs the opposite operation.

Color srgb_to_linear<>():Color

Returns the color converted to the linear color space. This method assumes the original color already is in the sRGB color space. See also linear_to_srgb which performs the opposite operation.

int to_abgr32<>():int

Returns the color converted to a 32-bit integer in ABGR format (each component is 8 bits). ABGR is the reversed version of the default RGBA format.

var color = Color(1, 0.5, 0.2) print(color.to_abgr32()) # Prints 4281565439
int to_abgr64<>():int

Returns the color converted to a 64-bit integer in ABGR format (each component is 16 bits). ABGR is the reversed version of the default RGBA format.

var color = Color(1, 0.5, 0.2) print(color.to_abgr64()) # Prints -225178692812801
int to_argb32<>():int

Returns the color converted to a 32-bit integer in ARGB format (each component is 8 bits). ARGB is more compatible with DirectX.

var color = Color(1, 0.5, 0.2) print(color.to_argb32()) # Prints 4294934323
int to_argb64<>():int

Returns the color converted to a 64-bit integer in ARGB format (each component is 16 bits). ARGB is more compatible with DirectX.

var color = Color(1, 0.5, 0.2) print(color.to_argb64()) # Prints -2147470541
String to_html<>( bool with_alpha=true, with_alpha:bool=true, ):String

Returns the color converted to an HTML hexadecimal color String in RGBA format, without the hash (#) prefix.

Setting with_alpha to false, excludes alpha from the hexadecimal string, using RGB format instead of RGBA format.

var white = Color(1, 1, 1, 0.5) var with_alpha = white.to_html() # Returns "ffffff7f" var without_alpha = white.to_html(false) # Returns "ffffff"
int to_rgba32<>():int

Returns the color converted to a 32-bit integer in RGBA format (each component is 8 bits). RGBA is Godot's default format.

var color = Color(1, 0.5, 0.2) print(color.to_rgba32()) # Prints 4286526463
int to_rgba64<>():int

Returns the color converted to a 64-bit integer in RGBA format (each component is 16 bits). RGBA is Godot's default format.

var color = Color(1, 0.5, 0.2) print(color.to_rgba64()) # Prints -140736629309441



All social media brands are registrated trademarks and belong to their respective owners.





CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
CONTACT IMPRINT TERMS OF USE PRIVACY © ROKOROJI ® 2021 rokojori.com
We are using cookies on this site. Read more... Wir benutzen Cookies auf dieser Seite. Mehr lesen...