Merriam-Webster defines color as “a phenomenon of light (such as red, brown, pink, or gray) or visual perception that enables one to differentiate otherwise identical objects.” In this essay, I will…
Okay, okay. We all know what colors are. Chickadee provides a data
type to represent color and some convenient procedures to work with
them in the (chickadee graphics color)
module. Colors are made
up of four components, or channels: red, green, blue, and alpha
(transparency.) Each of these values is expressed as a uniform
floating point value in the range [0, 1]. 0 means that color channel
is unrepresented in the resulting color, whereas 1 means that color
channel is at full intensity.
Making a color object is easy, and there’s a few ways to do it
depending on what’s most convenient. The first is make-color
,
where you specify each channel exactly as described above. This is
fully opaque magenta:
(make-color 1.0 0.0 1.0 1.0)
Many people are used to representing colors as 6 or 8 digit hexadecimal numbers, so Chickadee also allows that. Here’s magenta, again:
(rgba #xFF00FFFF) (rgb #xFF00FF) ; equivalent to the above
Return a new color object with a red value of r, a green value of g, a blue value of b, and an alpha (transparency) value of a. All values are clamped to the range [0, 1].
Return a new color object using the values of the first 32 bits of color-code. Each channel occupies 8 bits. Starting from the most significant bit, red is first, followed by green, then blue, then alpha. Color codes are often represented as 6 or 8 digit hexadecimal numbers in various other programs.
Like rgba
, but color-code is a 24 bit code with no alpha
channel.
Return #t
if obj is a color object.
Return the red channel of color.
Return the green channel of color.
Return the blue channel of color.
Return the alpha channel of color.
Return a new color that is white (RGB channels set to 1) with an alpha channel value of alpha. This can be useful for creating a color that can be multiplied against another color to make it more transparent.
Convert the hexadecimal color code in the string s to a color object. The following string formats are supported:
(string->color "#FF00FFFF") (string->color "FF00FFFF") (string->color "#FF00FF") (string->color "FF00FF")
Multiply the color a with the color or number b and return a new color with the result.
Add the color a to the color b and return a new color with the result.
Subtract the color b from the color a and return a new color with the result.
Invert the red, green, and blue channels of color and return a new color with the result.
Linearly interpolate the colors start and end using the factor alpha, a number in the range [0, 1].
For convenience, Chickadee comes with some basic colors predefined:
For fun, there are also predefined colors for the classic Tango color palette.