struct Celestine::Color

Overview

Represents an RGBA/HSLA color with parsing, conversions, and manipulation utilities.

Defined in:

color/color.cr

Constructors

Instance Method Summary

Constructor Detail

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

Parses hex color strings: "#RGB", "#RGBA", "#RRGGBB", or "#RRGGBBAA"


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

Creates a color from HSL (h: 0-360, s: 0.0-1.0 or 0-100, l: 0.0-1.0 or 0-100)


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

[View source]
def self.rgb(r : Number, g : Number, b : Number, a : Number = 1.0) : Color #

Creates a color from RGB integers (0-255) and alpha (0.0-1.0)


[View source]

Instance Method Detail

def a : Float64 #

[View source]
def b : UInt8 #

[View source]
def complementary : Color #

Returns the complementary color (180 degree hue shift)


[View source]
def darken(amount : Number) : Color #

Darkens color by a fraction (0.0 - 1.0)


[View source]
def desaturate(amount : Number) : Color #

Decreases saturation by a fraction (0.0 - 1.0)


[View source]
def g : UInt8 #

[View source]
def lighten(amount : Number) : Color #

Lightens color by a fraction (0.0 - 1.0)


[View source]
def mix(other : Color, weight : Number = 0.5) : Color #

Mixes this color with another color by weight (0.0 = self, 1.0 = other)


[View source]
def r : UInt8 #

[View source]
def saturate(amount : Number) : Color #

Increases saturation by a fraction (0.0 - 1.0)


[View source]
def to_hex(include_alpha : Bool = false) : String #

Formats as CSS hex string


[View source]
def to_hsl : Tuple(Float64, Float64, Float64) #

Converts this color to HSL representation: {hue, saturation, lightness}


[View source]
def to_rgb : String #

Formats as CSS rgb(...) string


[View source]
def to_rgba : String #

Formats as CSS rgba(...) string


[View source]
def to_s(io : IO) : Nil #

Default string conversion: hex when fully opaque, rgba when translucent


[View source]
def to_s : String #
Description copied from class Object

Returns a nicely readable and concise string representation of this object, typically intended for users.

This method should usually not be overridden. It delegates to #to_s(IO) which can be overridden for custom implementations.

Also see #inspect.


[View source]
def with_alpha(new_alpha : Number) : Color #

Returns a copy of this color with adjusted alpha


[View source]