struct
Godot::Color
- Godot::Color
- Struct
- Value
- Object
Overview
A color represented in RGBA format with 32-bit floating point precision per channel.
Defined in:
lapis/color.crlibgodot/types/color.cr
Constant Summary
-
BLACK =
Color.new(0.0_f32, 0.0_f32, 0.0_f32, 1.0_f32) -
BLUE =
Color.new(0.0_f32, 0.0_f32, 1.0_f32, 1.0_f32) -
CYAN =
Color.new(0.0_f32, 1.0_f32, 1.0_f32, 1.0_f32) -
GRAY =
Color.new(0.5_f32, 0.5_f32, 0.5_f32, 1.0_f32) -
GREEN =
Color.new(0.0_f32, 1.0_f32, 0.0_f32, 1.0_f32) -
MAGENTA =
Color.new(1.0_f32, 0.0_f32, 1.0_f32, 1.0_f32) -
ORANGE =
Color.new(1.0_f32, 0.65_f32, 0.0_f32, 1.0_f32) -
RED =
Color.new(1.0_f32, 0.0_f32, 0.0_f32, 1.0_f32) -
TRANSPARENT =
Color.new(0.0_f32, 0.0_f32, 0.0_f32, 0.0_f32) -
WHITE =
Color.new(1.0_f32, 1.0_f32, 1.0_f32, 1.0_f32) -
YELLOW =
Color.new(1.0_f32, 1.0_f32, 0.0_f32, 1.0_f32)
Constructors
- .cmyk(c : Number, m : Number, y : Number, k : Number, a : Number = 1.0) : Color
- .cmyk(cmyk : CMYK) : Color
- .from_cmyk(c : Number, m : Number, y : Number, k : Number, a : Number = 1.0) : Color
- .from_cmyk(cmyk : CMYK) : Color
- .from_hsl(h : Number, s : Number, l : Number, a : Number = 1.0) : Color
- .from_hsl(hsl : HSL) : Color
- .from_hsv(h : Number, s : Number, v : Number, a : Number = 1.0) : Color
-
.from_hsv(hsv : HSV) : Color
Constructs a Color from an intermediary HSV struct
- .from_html(hex : String) : Color
- .from_lab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color
- .from_oklab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color
- .from_oklch(l : Number, c : Number, h : Number, alpha : Number = 1.0) : Color
-
.from_temperature(kelvin : Number, alpha : Number = 1.0) : Color
Constructs a Color corresponding to the blackbody radiation temperature in Kelvin.
- .from_xyz(x : Number, y : Number, z : Number, a : Number = 1.0) : Color
-
.hex(hex_str : String) : Color
Creates a Color from a hex string (e.g.
- .hsl(h : Number, s : Number, l : Number, a : Number = 1.0) : Color
- .hsl(hsl : HSL) : Color
-
.hsv(h : Number, s : Number, v : Number, a : Number = 1.0) : Color
Shorthand alias to from_hsv
-
.hsv(hsv : HSV) : Color
Shorthand alias to from_hsv(hsv)
- .lab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color
- .new(r : Float32 = 1.0_f32, g : Float32 = 1.0_f32, b : Float32 = 1.0_f32, a : Float32 = 1.0_f32)
- .new(r : Number, g : Number, b : Number, a : Number = 1.0)
- .new(pointer : Pointer(Void))
- .new(rgba32 : UInt32)
- .new(hsv : HSV)
- .new(hsl : HSL)
- .new(cmyk : CMYK)
- .new(xyz : XYZ)
- .new(lab : Lab)
- .new(oklab : Oklab)
- .new(oklch : Oklch)
- .oklab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color
- .oklch(l : Number, c : Number, h : Number, alpha : Number = 1.0) : Color
-
.random(include_alpha : Bool = false) : Color
Generates a random RGB Color with alpha = 1.0 (or random alpha if include_alpha: true)
- .temperature(kelvin : Number, alpha : Number = 1.0) : Color
- .xyz(x : Number, y : Number, z : Number, a : Number = 1.0) : Color
Class Method Summary
- ._f_lab(t : Float32) : Float32
- ._f_lab_inv(t : Float32) : Float32
- ._linear_to_srgb(c : Float32) : Float32
- ._srgb_to_linear(c : Float32) : Float32
Instance Method Summary
- #!=(other : Color) : Bool
- #*(other : Color) : Color
- #*(scalar : Number) : Color
- #+(other : Color) : Color
- #-(other : Color) : Color
- #/(scalar : Number) : Color
- #==(other : Color) : Bool
- #a : Float32
- #a=(a : Float32)
-
#accessible_text_color : Color
Returns either pure Black or pure White depending on which provides greater contrast against this color.
-
#adjust_hsv(delta_h : Number = 0.0, delta_s : Number = 0.0, delta_v : Number = 0.0) : Color
Adjusts hue, saturation, and value by relative offsets
-
#analogous(angle : Float32 = 30.0_f32) : Tuple(Color, Color, Color)
Returns a 3-color analogous palette
- #b : Float32
- #b=(b : Float32)
-
#blend_hsv(other : Color, weight : Number = 0.5) : Color
Blends colors smoothly in cylindrical HSV space
-
#blend_lab(other : Color, weight : Number = 0.5) : Color
Perceptually blends colors in CIE-Lab* space
-
#blend_oklab(other : Color, weight : Number = 0.5) : Color
Perceptually blends colors in Oklab space
- #cmyk : CMYK
-
#complementary : Color
Returns the complementary color (opposite hue on color wheel, +180°)
-
#contrast_ratio(other : Color) : Float32
Calculates the WCAG 2.1 contrast ratio between this color and another color (range 1.0 to 21.0).
- #contrasted : Color
- #darkened(amount : Number) : Color
- #delta_e(other : Color) : Float32
- #g : Float32
- #g=(g : Float32)
-
#h : Float32
Hue component in range [0.0, 1.0]
- #h=(val : Number) : Void
- #hsl : HSL
-
#hsv : HSV
Shorthand for extracting the intermediary Godot::Color::HSV value struct
- #inverted : Color
- #is_equal_approx(other : Color) : Bool
- #lab : Lab
- #lerp(to : Color, weight : Number) : Color
- #lightened(amount : Number) : Color
-
#luminance : Float32
Perceptual relative luminance according to ITU-R BT.709
-
#meets_wcag_aa?(other : Color, large_text : Bool = false) : Bool
Checks whether this color has sufficient contrast with another color under WCAG AA standards.
-
#meets_wcag_aaa?(other : Color, large_text : Bool = false) : Bool
Checks whether this color has sufficient contrast with another color under WCAG AAA standards.
- #oklab : Oklab
- #oklch : Oklch
- #r : Float32
- #r=(r : Float32)
-
#s : Float32
Saturation component in range [0.0, 1.0]
- #s=(val : Number) : Void
-
#split_complementary(angle : Float32 = 30.0_f32) : Tuple(Color, Color, Color)
Returns a 3-color split-complementary palette
-
#tetradic : Tuple(Color, Color, Color, Color)
Returns a 4-color tetradic harmony (+90°, +180°, +270°)
- #to_argb32 : UInt32
- #to_cmyk : Tuple(Float32, Float32, Float32, Float32)
- #to_hsl : Tuple(Float32, Float32, Float32)
- #to_hsla : Tuple(Float32, Float32, Float32, Float32)
-
#to_hsv : Tuple(Float32, Float32, Float32)
Computes and returns the Hue, Saturation, and Value components in range [0.0, 1.0]
-
#to_hsv_struct : HSV
Returns an intermediary mutable Godot::Color::HSV value struct
-
#to_hsva : Tuple(Float32, Float32, Float32, Float32)
Computes and returns the Hue, Saturation, Value, and Alpha components in range [0.0, 1.0]
- #to_html(include_alpha : Bool = true) : String
- #to_lab : Tuple(Float32, Float32, Float32)
- #to_oklab : Tuple(Float32, Float32, Float32)
- #to_oklch : Tuple(Float32, Float32, Float32)
- #to_rgba32 : UInt32
-
#to_s(io : IO) : Void
Same as
#inspect(io). - #to_xyz : Tuple(Float32, Float32, Float32)
-
#triadic : Tuple(Color, Color, Color)
Returns a 3-color triadic harmony (+120°, +240°)
-
#v : Float32
Value component in range [0.0, 1.0]
- #v=(val : Number) : Void
-
#with_alpha(val : Number) : Color
Returns a new Color with modified alpha
-
#with_h(val : Number) : Color
Returns a new Color with modified hue
- #with_hsl(*, h : Number | Nil = nil, s : Number | Nil = nil, l : Number | Nil = nil, a : Number | Nil = nil) : Color
-
#with_hsv(*, h : Number | Nil = nil, s : Number | Nil = nil, v : Number | Nil = nil, a : Number | Nil = nil) : Color
Returns a new Color with multiple HSV/A components altered
-
#with_s(val : Number) : Color
Returns a new Color with modified saturation
-
#with_v(val : Number) : Color
Returns a new Color with modified value
- #xyz : XYZ
Instance methods inherited from class Object
try?(&)try? try?
Constructor Detail
Constructs a Color corresponding to the blackbody radiation temperature in Kelvin.
Creates a Color from a hex string (e.g. "#ff0000" or "ff0000")
Shorthand alias to from_hsv
Generates a random RGB Color with alpha = 1.0 (or random alpha if include_alpha: true)
Class Method Detail
Instance Method Detail
Returns either pure Black or pure White depending on which provides greater contrast against this color.
Adjusts hue, saturation, and value by relative offsets
Returns a 3-color analogous palette
Blends colors smoothly in cylindrical HSV space
Perceptually blends colors in CIE-Lab* space
Perceptually blends colors in Oklab space
Calculates the WCAG 2.1 contrast ratio between this color and another color (range 1.0 to 21.0).
Checks whether this color has sufficient contrast with another color under WCAG AA standards.
Checks whether this color has sufficient contrast with another color under WCAG AAA standards.
Returns a 3-color split-complementary palette
Returns a 4-color tetradic harmony (+90°, +180°, +270°)
Computes and returns the Hue, Saturation, and Value components in range [0.0, 1.0]
Computes and returns the Hue, Saturation, Value, and Alpha components in range [0.0, 1.0]