struct Godot::Color

Overview

A color represented in RGBA format with 32-bit floating point precision per channel.

Defined in:

lapis/color.cr
libgodot/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

Class Method Summary

Instance Method Summary

Instance methods inherited from class Object

try?(&)
try?
try?

Constructor Detail

def self.cmyk(c : Number, m : Number, y : Number, k : Number, a : Number = 1.0) : Color #

def self.cmyk(cmyk : CMYK) : Color #

def self.from_cmyk(c : Number, m : Number, y : Number, k : Number, a : Number = 1.0) : Color #

def self.from_cmyk(cmyk : CMYK) : Color #

def self.from_hsl(h : Number, s : Number, l : Number, a : Number = 1.0) : Color #

def self.from_hsl(hsl : HSL) : Color #

def self.from_hsv(h : Number, s : Number, v : Number, a : Number = 1.0) : Color #

def self.from_hsv(hsv : HSV) : Color #

Constructs a Color from an intermediary HSV struct


def self.from_html(hex : String) : Color #

def self.from_lab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color #

def self.from_oklab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color #

def self.from_oklch(l : Number, c : Number, h : Number, alpha : Number = 1.0) : Color #

def self.from_temperature(kelvin : Number, alpha : Number = 1.0) : Color #

Constructs a Color corresponding to the blackbody radiation temperature in Kelvin.


def self.from_xyz(x : Number, y : Number, z : Number, a : Number = 1.0) : Color #

def self.hex(hex_str : String) : Color #

Creates a Color from a hex string (e.g. "#ff0000" or "ff0000")


def self.hsl(h : Number, s : Number, l : Number, a : Number = 1.0) : Color #

def self.hsl(hsl : HSL) : Color #

def self.hsv(h : Number, s : Number, v : Number, a : Number = 1.0) : Color #

Shorthand alias to from_hsv


def self.hsv(hsv : HSV) : Color #

Shorthand alias to from_hsv(hsv)


def self.lab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color #

def self.new(r : Float32 = 1.0_f32, g : Float32 = 1.0_f32, b : Float32 = 1.0_f32, a : Float32 = 1.0_f32) #

def self.new(r : Number, g : Number, b : Number, a : Number = 1.0) #

def self.new(pointer : Pointer(Void)) #

def self.new(rgba32 : UInt32) #

def self.new(hsv : HSV) #

def self.new(hsl : HSL) #

def self.new(cmyk : CMYK) #

def self.new(xyz : XYZ) #

def self.new(lab : Lab) #

def self.new(oklab : Oklab) #

def self.new(oklch : Oklch) #

def self.oklab(l : Number, a : Number, b : Number, alpha : Number = 1.0) : Color #

def self.oklch(l : Number, c : Number, h : Number, alpha : Number = 1.0) : Color #

def self.random(include_alpha : Bool = false) : Color #

Generates a random RGB Color with alpha = 1.0 (or random alpha if include_alpha: true)


def self.temperature(kelvin : Number, alpha : Number = 1.0) : Color #

def self.xyz(x : Number, y : Number, z : Number, a : Number = 1.0) : Color #

Class Method Detail

def self._f_lab(t : Float32) : Float32 #

def self._f_lab_inv(t : Float32) : Float32 #

def self._linear_to_srgb(c : Float32) : Float32 #

def self._srgb_to_linear(c : Float32) : Float32 #

Instance Method Detail

def !=(other : Color) : Bool #

def *(other : Color) : Color #

def *(scalar : Number) : Color #

def +(other : Color) : Color #

def -(other : Color) : Color #

def /(scalar : Number) : Color #

def ==(other : Color) : Bool #

def a : Float32 #

def a=(a : Float32) #

def accessible_text_color : Color #

Returns either pure Black or pure White depending on which provides greater contrast against this color.


def 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


def analogous(angle : Float32 = 30.0_f32) : Tuple(Color, Color, Color) #

Returns a 3-color analogous palette


def b : Float32 #

def b=(b : Float32) #

def blend_hsv(other : Color, weight : Number = 0.5) : Color #

Blends colors smoothly in cylindrical HSV space


def blend_lab(other : Color, weight : Number = 0.5) : Color #

Perceptually blends colors in CIE-Lab* space


def blend_oklab(other : Color, weight : Number = 0.5) : Color #

Perceptually blends colors in Oklab space


def cmyk : CMYK #

def complementary : Color #

Returns the complementary color (opposite hue on color wheel, +180°)


def contrast_ratio(other : Color) : Float32 #

Calculates the WCAG 2.1 contrast ratio between this color and another color (range 1.0 to 21.0).


def contrasted : Color #

def darkened(amount : Number) : Color #

def delta_e(other : Color) : Float32 #

def g : Float32 #

def g=(g : Float32) #

def h : Float32 #

Hue component in range [0.0, 1.0]


def h=(val : Number) : Void #

def hsl : HSL #

def hsv : HSV #

Shorthand for extracting the intermediary Godot::Color::HSV value struct


def inverted : Color #

def is_equal_approx(other : Color) : Bool #

def lab : Lab #

def lerp(to : Color, weight : Number) : Color #

def lightened(amount : Number) : Color #

def luminance : Float32 #

Perceptual relative luminance according to ITU-R BT.709


def meets_wcag_aa?(other : Color, large_text : Bool = false) : Bool #

Checks whether this color has sufficient contrast with another color under WCAG AA standards.


def meets_wcag_aaa?(other : Color, large_text : Bool = false) : Bool #

Checks whether this color has sufficient contrast with another color under WCAG AAA standards.


def oklab : Oklab #

def oklch : Oklch #

def r : Float32 #

def r=(r : Float32) #

def s : Float32 #

Saturation component in range [0.0, 1.0]


def s=(val : Number) : Void #

def split_complementary(angle : Float32 = 30.0_f32) : Tuple(Color, Color, Color) #

Returns a 3-color split-complementary palette


def tetradic : Tuple(Color, Color, Color, Color) #

Returns a 4-color tetradic harmony (+90°, +180°, +270°)


def to_argb32 : UInt32 #

def to_cmyk : Tuple(Float32, Float32, Float32, Float32) #

def to_hsl : Tuple(Float32, Float32, Float32) #

def to_hsla : Tuple(Float32, Float32, Float32, Float32) #

def to_hsv : Tuple(Float32, Float32, Float32) #

Computes and returns the Hue, Saturation, and Value components in range [0.0, 1.0]


def to_hsv_struct : HSV #

Returns an intermediary mutable Godot::Color::HSV value struct


def to_hsva : Tuple(Float32, Float32, Float32, Float32) #

Computes and returns the Hue, Saturation, Value, and Alpha components in range [0.0, 1.0]


def to_html(include_alpha : Bool = true) : String #

def to_lab : Tuple(Float32, Float32, Float32) #

def to_oklab : Tuple(Float32, Float32, Float32) #

def to_oklch : Tuple(Float32, Float32, Float32) #

def to_rgba32 : UInt32 #

def to_s(io : IO) : Void #
Description copied from struct Struct

Same as #inspect(io).


def to_xyz : Tuple(Float32, Float32, Float32) #

def triadic : Tuple(Color, Color, Color) #

Returns a 3-color triadic harmony (+120°, +240°)


def v : Float32 #

Value component in range [0.0, 1.0]


def v=(val : Number) : Void #

def with_alpha(val : Number) : Color #

Returns a new Color with modified alpha


def with_h(val : Number) : Color #

Returns a new Color with modified hue


def with_hsl(*, h : Number | Nil = nil, s : Number | Nil = nil, l : Number | Nil = nil, a : Number | Nil = nil) : Color #

def 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


def with_s(val : Number) : Color #

Returns a new Color with modified saturation


def with_v(val : Number) : Color #

Returns a new Color with modified value


def xyz : XYZ #