Documentation
See Color Art.
Usage
Add Dependency
[]
= "0.2"
Color generator
Create color from string
You can use the from_str method to construct a color from a string.
use Color;
use FromStr;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
let color = from_str.unwrap;
Create color from number
You can use the from_num method to construct a color from a number.
For example:
use Color;
let color = from_num.unwrap;
let color = from_num.unwrap;
Create color from name
You can use the from_name method to construct a color from a name.
For example:
use Color;
let color = from_name.unwrap;
Create color from color space
You can use the from_<color_space> method to construct a color from a color space.
Currently supported color spaces:
rgbrgbahslhsvcmykhex
More color spaces will be supported in the future.
For example:
use Color;
let color = from_rgb.unwrap;
let color = from_rgba.unwrap;
let color = from_hsl.unwrap;
let color = from_hsv.unwrap;
let color = from_cmyk.unwrap;
let color = from_hex.unwrap;
More examples can be found in Construct from color spaces.
Other color generator methods
- random - Generate a random color.
- mix - Mix two colors.
- blend - Blend two colors with a blending mode.
- average - Average a list of colors.
Color conversion
Stringify a color
Stringify a color to a string.
You can use the hex, rgb, rgba, hsl, hsla, hsv, hsi, hwb, cmyk, xyz, yuv, YCbCr, lab, name method to stringify a color to a string.
For example:
use Color;
use FromStr;
let color = from_str.unwrap;
color.hex; // "#ffff00"
color.rgb; // "rgb(255, 255, 0)"
color.rgba; // "rgba(255, 255, 0, 1)"
color.hsl; // "hsl(60, 100%, 50%)"
color.hsla; // "hsl(60, 100%, 50%, 1)"
color.hsv; // "hsv(60, 100%, 100%)"
color.hsi; // "hsi(60, 100%, 66.67%)"
color.hwb; // "hwb(60, 0%, 0%)"
color.cmyk; // "cmyk(0%, 0%, 100%, 0%)"
color.xyz; // "xyz(0.932231, 0.975339, 0.502949)"
color.yuv; // "yuv(0.886, -0.4359, 0.1)"
color.ycbcr; // "YCbCr(225.93, 0.5755, 148.7269)"
color.name; // "yellow"
color.lab; // "lab(97.14, -21.55, 94.48)"
Color Channel
You can use the red, green, blue, alpha, hue, saturation, lightness, hsv_hue, hsv_saturation, hsv_value, luma, luminance, gray method to extract the color channel.
use Color;
use FromStr;
let color = from_str.unwrap;
color.red; // 171
color.green; // 205
color.blue; // 239
color.alpha; // 1.0
color.hue; // 210.0
color.saturation; // 0.68
color.lightness; // 0.8039
color.hsv_hue; // 210.0
color.hsv_saturation; // 0.2845
color.hsv_value; // 0.9373
color.luma; // 0.59
color.luminance; // 0.79
color.gray; // 198.71
Color Operation
- darken - Darken a color.
- lighten - Lighten a color.
- saturate - Saturate a color.
- desaturate - Desaturate a color.
- greyscale - Greyscale a color.
- fade - Fade a color.
- fade in - Fade in a color.
- fade out - Fade out a color.
- spin - Spin a color.
- mix - Mix with another color.
- tint - Tint a color.
- shade - Shade a color.
More details, please refer to Color Operation.
Made with ❤️ by JiatLn.