Utilities for working with color in Koto.
At the core of the library is the Color
type, with various initializers
available.
For convenience, the color module itself is callable:
|String| -> Color
Equivalent to calling color.named.
|Number, Number, Number| -> Color
Equivalent to calling color.rgb.
|Number, Number, Number, Number| -> Color
Equivalent to calling color.rgba.
Example:
color 'red'
# -> Color {r: 1, g: 0, b: 0, a: 1}
|Number, Number, Number| -> Color
Returns a color produced from hue, saturation, and lightness components.
The hue component is specified in degrees.
The saturation and lightness components are specified as numbers between 0
and 1
.
color.hsl 180, 1, 0.25
# -> Color {r: 0, g: 0.5, b: 0.5, a: 1}
|Number, Number, Number| -> Color
Returns a color produced from hue, saturation, and value components.
The hue component is specified in degrees.
The saturation and value components are specified as numbers between 0
and 1
.
color.hsv 90, 0.5, 1
# -> Color {r: 0.75, g: 1, b: 0.5, a: 1}
|String| -> Color
Returns a color corresponding to one of the named colors listed in the SVG color keywords specification.
color.named 'yellow'
# -> Color {r: 1, g: 1, b: 0, a: 1}
|Number, Number, Number| -> Color
Returns a color produced from red, green, and blue components.
The RGB components are specified as numbers between 0
and 1
.
color.rgb 0.5, 0.1, 0.9
# -> Color {r: 0.5, g: 0.1, b: 0.9, a: 1}
|Number, Number, Number, Number| -> Color
Returns a color produced from red, green, blue, and alpha components.
The RGBA components are specified as numbers between 0
and 1
.
color.rgba 0.2, 0.4, 0.3, 0.5
# -> Color {r: 0.2, g: 0.4, b: 0.3, a: 0.5}
The color
modules core color type, represented by RGBA components.
All arithemetic operations are implemented, accepting colors or numbers as input. The color's RGBA components are iterable.
color('red') + color('lime')
# -> Color {r: 1, g: 1, b: 0, a: 1}
r, g, b = color('yellow')
r, g, b
# -> (1.0, 1.0, 0.0)
|Color| -> Number
Returns the color's red component.
color('black').r()
# -> 0.0
color('yellow').red()
# -> 1.0
|Color| -> Number
Returns the color's green component.
color('black').g()
# -> 0.0
color('yellow').green()
# -> 1.0
|Color| -> Number
Returns the color's blue component.
color('black').b()
# -> 0.0
color('cyan').blue()
# -> 1.0
|Color| -> Number
Returns the color's blue component.
color('black').b()
# -> 0.0
color('cyan').blue()
# -> 1.0
|Color| -> Number
Returns the color's alpha component.
color('black').a()
# -> 1.0
color(1, 1, 1, 0.5).alpha()
# -> 0.5
|Color, Number| -> Color
Sets the color's red component, and returns the color.
color('black').set_r(1.0)
# -> Color {r: 1, g: 0, b: 0, a: 1}
color('red').set_red(0.0)
# -> Color {r: 0, g: 0, b: 0, a: 1}
|Color, Number| -> Color
Sets the color's green component, and returns the color.
color('black').set_g(1.0)
# -> Color {r: 0, g: 1, b: 0, a: 1}
color('red').set_green(1.0)
# -> Color {r: 1, g: 1, b: 0, a: 1}
|Color, Number| -> Color
Sets the color's blue component, and returns the color.
color('black').set_b(1.0)
# -> Color {r: 0, g: 0, b: 1, a: 1}
color('red').set_blue(1.0)
# -> Color {r: 1, g: 0, b: 1, a: 1}
|Color, Number| -> Color
Sets the color's blue component, and returns the color.
color('black').set_a(0.5)
# -> Color {r: 0, g: 0, b: 0, a: 0.5}
color('red').set_alpha(0.2)
# -> Color {r: 1, g: 0, b: 0, a: 0.2}
|Color, Color| -> Color
Returns a new color representing an even mix of the two input colors.
|Color, Color, Number| -> Color
Returns a new color representing a weighted mix of the two input colors.
The weight is specified by a number between 0
and 1
, with values closer to
0
producing results closer to the first color, and values closer to 1
producing results closer to the second color.
a, b = color('red'), color('blue')
a.mix b
# -> Color {r: 0.5, g: 0, b: 0.5, a: 1}
a.mix b, 0.25
# -> Color {r: 0.75, g: 0, b: 0.25, a: 1}