Reads a hex color into an { r, g, b } object with channels from 0 to 255.
The text may start with or without #; anything else than six hex digits throws an error.
Example: '#FF5733' -> { r: 255, g: 87, b: 51 }
The hex color
The color object with channels from 0 to 255
Writes three channel values as a hex color.
min and max say which range the values use; a range other than 0 to 255 is remapped
first, so channels from 0 to 1 work as well.
Example: r 255, g 87, b 51 in [0,255] -> '#ff5733'; r 1, g 0.5, b 0.2 in [0,1] -> '#ff8033'
The red, green and blue values and their range
The hex color
Writes an { r, g, b } color as a hex color.
min and max say which range the channels use; a range other than 0 to 255 is remapped
first.
Example: { r: 1, g: 0.5, b: 0.2 } in [0,1] -> '#ff8033'
The color object and the range its channels use
The hex color
Reads a hex color into an { r, g, b } object with the channels remapped to a range of your
choice.
Example: '#FF5733' mapped to [0,1] -> { r: 1, g: 0.341, b: 0.2 }
The hex color and the range to map the channels to
The color object with channels in that range
Passes a hex color through unchanged, so a color can be given a name and reused.
Example: '#FF5733' -> '#FF5733'
The hex color
The same hex color
Passes an { r, g, b, a } color with color channels from 0 to 255 and opacity from 0 to 1
through unchanged, so it can be given a name and reused.
Example: { r: 255, g: 87, b: 51, a: 1 } -> the same object
The color object
The same color object
Builds an { r, g, b } color from three separate channel values from 0 to 255.
Example: r 255, g 87, b 51 -> { r: 255, g: 87, b: 51 }
The red, green and blue values
The color object
Builds an { r, g, b } color from three separate channel values from 0 to 1.
Example: r 1, g 0.34, b 0.2 -> { r: 1, g: 0.34, b: 0.2 }
The red, green and blue values
The color object
Reads the red channel of a hex color, remapped to a range of your choice.
Example: '#FF5733' in [0,1] -> 1
The hex color and the range to map the channel to
The red channel in that range
Reads the green channel of a hex color, remapped to a range of your choice.
Example: '#FF5733' in [0,1] -> 0.341
The hex color and the range to map the channel to
The green channel in that range
Reads the blue channel of a hex color, remapped to a range of your choice.
Example: '#FF5733' in [0,1] -> 0.2
The hex color and the range to map the channel to
The blue channel in that range
Inverts a hex color, turning each channel into its opposite: 255 minus the value.
With blackAndWhite on, the result is plain black for a light color or white for a dark
one, which suits text on a colored background.
Example: '#FF5733' -> '#00a8cc'; with blackAndWhite -> '#ffffff'
The hex color and whether to reduce the result to black or white
The inverted hex color
Reads the red channel of an { r, g, b } color.
Example: { r: 255, g: 87, b: 51 } -> 255
The color object
The red channel, in whatever range the object uses
Reads the green channel of an { r, g, b } color.
Example: { r: 255, g: 87, b: 51 } -> 87
The color object
The green channel, in whatever range the object uses
Reads the blue channel of an { r, g, b } color.
Example: { r: 255, g: 87, b: 51 } -> 51
The color object
The blue channel, in whatever range the object uses
Colors in the two forms the library uses: a hex text such as
#ff5733, and an object{ r, g, b }or{ r, g, b, a }whose channels run either from 0 to 255 or from 0 to 1. The methods here build colors in each form, convert between them with an explicit channel range, read single channels and invert a color.