A rust crate for working with colors and color spaces.
See Color Art.
toml
[dependencies]
color-art = "0.3"
You can use the from_str
method to construct a color from a string.
Currently supported color formats
rgb
/ rgba
hex
hsl
/ hsla
hsv
hsi
hwb
cmyk
xyz
yiq
yuv
YCbCr
lab
named color
For example
```rust use color_art::Color; use std::str::FromStr;
let color = Color::fromstr("rgb(255, 255, 0)").unwrap(); let color = Color::fromstr("rgba(255, 255, 0, 0.5)").unwrap(); let color = Color::fromstr("#ffff00").unwrap(); let color = Color::fromstr("hsl(60, 100%, 50%)").unwrap(); let color = Color::fromstr("hsla(60, 100%, 50%, 0.6)").unwrap(); let color = Color::fromstr("hsv(60, 100%, 100%)").unwrap(); let color = Color::fromstr("hsi(60, 100%, 66.67%)").unwrap(); let color = Color::fromstr("hwb(60, 0%, 0%)").unwrap(); let color = Color::fromstr("cmyk(0%, 0%, 100%, 0%)").unwrap(); let color = Color::fromstr("xyz(0.769975, 0.927808, 0.138526)").unwrap(); let color = Color::fromstr("yiq(0.886, 0.32126, -0.31114)").unwrap(); let color = Color::fromstr("yuv(0.886, -0.4359, 0.1)").unwrap(); let color = Color::fromstr("YCbCr(225.93, 0.5755, 148.7269)").unwrap(); let color = Color::fromstr("lab(97.14, -21.55, 94.48)").unwrap(); let color = Color::from_str("yellow").unwrap(); ```
You can use the from_num
method to construct a color from a number.
For example:
```rust use color_art::Color;
let color = Color::fromnum(16776960).unwrap(); let color = Color::fromnum(0xffff00).unwrap(); ```
You can use the from_name
method to construct a color from a name.
For example:
```rust use color_art::Color;
let color = Color::from_name("yellow").unwrap(); ```
You can use the from_<color_space>
method to construct a color from a color space.
Currently supported color spaces:
rgb
rgba
hsl
hsv
cmyk
hex
More color spaces will be supported in the future.
For example:
```rust use color_art::Color;
let color = Color::fromrgb(255, 255, 0).unwrap(); let color = Color::fromrgba(255, 255, 0, 0.5).unwrap(); let color = Color::fromhsl(60.0, 1.0, 0.5).unwrap(); let color = Color::fromhsv(60.0, 1.0, 1.0).unwrap(); let color = Color::fromcmyk(0.0, 0.0, 1.0, 0.0).unwrap(); let color = Color::fromhex("#ffff00").unwrap(); ```
More examples can be found in Construct from color spaces.
Stringify a color to a string.
Refer to Construct from string.
Extract the color channels.
Refer to Color Channels.
Color operation functions.
Refer to Color Operations.
Made with ❤️ by JiatLn.