#color-space #color #color-string #art

bin+lib color-art

A rust crate for working with colors and color spaces

31 releases

0.3.8 Mar 31, 2024
0.3.7 Sep 20, 2023
0.3.5 Aug 30, 2023
0.3.2 Jun 27, 2023
0.2.0 Dec 30, 2022

#61 in Images

Download history 16/week @ 2024-07-29 23/week @ 2024-08-05 46/week @ 2024-08-12 32/week @ 2024-08-19 50/week @ 2024-08-26 28/week @ 2024-09-02 24/week @ 2024-09-09 29/week @ 2024-09-16 131/week @ 2024-09-23 39/week @ 2024-09-30 7/week @ 2024-10-07 68/week @ 2024-10-14 31/week @ 2024-10-21 21/week @ 2024-10-28 53/week @ 2024-11-04 4/week @ 2024-11-11

113 downloads per month
Used in 7 crates

MIT license

175KB
4K SLoC


ColorArt - A rust crate for working with colors and color spaces.

Color Art

A rust crate for working with colors and color spaces.

github crates.io docs.rs


Documentation

See Color Art.

Usage

Add Dependency

[dependencies]
color-art = "0.3"

Color generator

Create color from string

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
use color_art::Color;
use std::str::FromStr;

let color = Color::from_str("rgb(255, 255, 0)").unwrap();
let color = Color::from_str("rgba(255, 255, 0, 0.5)").unwrap();
let color = Color::from_str("#ffff00").unwrap();
let color = Color::from_str("hsl(60, 100%, 50%)").unwrap();
let color = Color::from_str("hsla(60, 100%, 50%, 0.6)").unwrap();
let color = Color::from_str("hsv(60, 100%, 100%)").unwrap();
let color = Color::from_str("hsi(60, 100%, 66.67%)").unwrap();
let color = Color::from_str("hwb(60, 0%, 0%)").unwrap();
let color = Color::from_str("cmyk(0%, 0%, 100%, 0%)").unwrap();
let color = Color::from_str("xyz(0.769975, 0.927808, 0.138526)").unwrap();
let color = Color::from_str("yiq(0.886, 0.32126, -0.31114)").unwrap();
let color = Color::from_str("yuv(0.886, -0.4359, 0.1)").unwrap();
let color = Color::from_str("YCbCr(225.93, 0.5755, 148.7269)").unwrap();
let color = Color::from_str("lab(97.14, -21.55, 94.48)").unwrap();
let color = Color::from_str("yellow").unwrap();

Create color from number

You can use the from_num method to construct a color from a number.

For example:

use color_art::Color;

let color = Color::from_num(16776960).unwrap();
let color = Color::from_num(0xffff00).unwrap();

Create color from name

You can use the from_name method to construct a color from a name.

For example:

use color_art::Color;

let color = Color::from_name("yellow").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:

  • rgb
  • rgba
  • hsl
  • hsv
  • cmyk
  • hex

More color spaces will be supported in the future.

For example:

use color_art::Color;

let color = Color::from_rgb(255, 255, 0).unwrap();
let color = Color::from_rgba(255, 255, 0, 0.5).unwrap();
let color = Color::from_hsl(60.0, 1.0, 0.5).unwrap();
let color = Color::from_hsv(60.0, 1.0, 1.0).unwrap();
let color = Color::from_cmyk(0.0, 0.0, 1.0, 0.0).unwrap();
let color = Color::from_hex("#ffff00").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.

Refer to Construct from string.

Color Channels

Extract the color channels.

Refer to Color Channels.

Color Operations

Color operation functions.

Refer to Color Operations.


Made with ❤️ by JiatLn.

License

MIT License © 2022-Present JiatLn

Dependencies

~0.6–1.2MB
~26K SLoC