class ColorUtil::Color
- ColorUtil::Color
- Reference
- Object
Overview
Specifies a 24 bit color.
Included Modules
- YAML::Serializable
Defined in:
colorutil/color.crConstructors
-
.from_hex(color : Int32 | UInt32) : Color
Creates a color from an rgb hexidecimal value.
- .from_hex(color : String) : Color
-
.from_hsl(h : Float64, s : Float64, l : Float64) : Color
Creates a
Color
using HSLuv hsl components. -
.from_rgb(r : Number, g : Number, b : Number) : Color
Creates a
Color
from individual rgb values. - .from_spectrum(spectrum : Indexable) : Color
- .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
-
.random : Color
Generates a random
Color
.
Class Method Summary
-
.mix(start : Color, stop : Color, frac)
TODO Refactor to use the interpolation function Interpolates between two colors.
Instance Method Summary
-
#==(other : Color) : Bool
True if and only if each rgb color component is equal among both colors.
-
#approx_contrast(other : Color) : Float64
Returns the luminance contrast ratio between this color and another.
-
#approx_relative_luminance : Float64
Computes the approximate relative luminance of this color.
- #b : UInt8
- #b=(b)
-
#contrast(other : Color) : Float64
Returns the luminance contrast ratio between this color and another.
- #g : UInt8
- #g=(g)
-
#generate(contrast : Float64, hue : Float64, saturation : Float64, min_lightness : Float64 = 0, max_lightness : Float64 = 100) : Color
Generates a new color that has a specified contrast ratio to
self
. - #h : Float64
- #l : Float64
- #r : UInt8
- #r=(r)
-
#relative_luminance : Float64
Returns the relative luminance of this color, as defined by https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests.
- #rgb : NamedTuple(r: UInt8, g: UInt8, b: UInt8)
- #s : Float64
-
#to_a : Array(Float64)
Returns an [h, s, l] array storing color data.
-
#to_hex : UInt32
Returns the raw 24-bit integer value that represents this color.
-
#to_hex_string : String
Returns a human readable hex color code - e.g.
-
#to_s(io : IO) : Nil
By default, the string version of a color is it's hex string.
Constructor Detail
Creates a color from an rgb hexidecimal value. For example,
Color.from_hex(0xff00ff)
creates the fuchsia usually described as
"#ff00ff".
Creates a Color
using HSLuv hsl components.
Creates a Color
from individual rgb values.
Class Method Detail
TODO Refactor to use the interpolation function
Interpolates between two colors. When frac == 0
, returns
start
. As frac
approaches 1, the function returns a color
closer and closer to stop
.
Instance Method Detail
True if and only if each rgb color component is equal among both colors.
Returns the luminance contrast ratio between this color and another. Computed using approximate relative luminance. Overall, this function has an error of at most 20% on the exact contrast, but note that this error is much smaller when colors are similar. So, for determining if two colors are readable together, this is likely accurate enough.
Computes the approximate relative luminance of this color.
See ColorUtil#approx_relative_luminance
Returns the luminance contrast ratio between this color and another. Computed using WCAG relative luminance.
Generates a new color that has a specified contrast ratio to
self
. As contrast ratio is computed only using lightness,
this leaves hue and saturation as free parameters which the user
can choose.
Returns the relative luminance of this color, as defined by https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests. This is needed to compute contrast acording to the web content accessibility guidelines.
Returns the raw 24-bit integer value that represents this color. For example, pure blue (0x0000ff) would return the integer 255. This is effectively the inverse to the constructor "from_hex".
Returns a human readable hex color code - e.g. "#ff00ff" for pure fuchsia.