A rust crate for working with colors and color spaces.

Overview

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.2"

Color generator

You can use the from_str method to construct a color from a string.

Currently supported color formats:

  • RGB
  • RGBA
  • HEX
  • HSL
  • HSV
  • HWB
  • CMYK
  • Named color from w3cx11

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("hsv(60, 100%, 100%)").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("yellow").unwrap();

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, hsv, hwb, name method to stringify a color to a string. For example:

use color_art::Color;
use std::str::FromStr;

let color = Color::from_str("#ffff00").unwrap();
color.hex(); // "#ffff00"
color.rgb(); // "rgb(255, 255, 0)"
color.rgba(); // "rgba(255, 255, 0, 1)"
color.hsl(); // "hsl(60, 100%, 50%)"
color.hsv(); // "hsv(60, 100%, 100%)"
color.hwb(); // "hwb(60, 0%, 0%)"
color.cmyk(); // "cmyk(0%, 0%, 100%, 0%)"
color.name(); // "yellow"

Color Channel

You can use the red, green, blue, alpha, hue, saturation, lightness, hsv_hue, hsv_saturation, hsv_value, luma, luminance method to extract the color channel.

use color_art::Color;
use std::str::FromStr;

let color = Color::from_str("#abcdef").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.8

color.hsv_hue(); // 210.0
color.hsv_saturation(); // 0.28
color.hsv_value(); // 0.94

color.luma(); // 0.59
color.luminance(); // 0.79

Color Operation

More details, please refer to Color Operation.


Made with ❤️ by JiatLn.

License

MIT License © 2022-Present JiatLn

You might also like...
Detects whether a terminal supports color, and gives details about that support

Detects whether a terminal supports color, and gives details about that support. It takes into account the NO_COLOR environment variable. This crate i

Convert your favorite images and wallpapers with your favorite color palettes/themes
Convert your favorite images and wallpapers with your favorite color palettes/themes

dipc doprz' image palette converter Convert your favorite images and wallpapers with your favorite color palettes/themes Color Palettes/Themes catppuc

A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sanctity is an acronym for rust ansi16 color test utility
Sanctity is an acronym for rust ansi16 color test utility

sanctity 🌈 sanctity is an acronym for rust ansi16 color test utility. It prints your own text or the default text in all of the 16 terminal colors.

A small script in rust to get the cpu usage in %'s with a gradient color for the text
A small script in rust to get the cpu usage in %'s with a gradient color for the text

cpu_usage-polybar A small script in rust to get the cpu usage in %'s with a gradient color for the text To get it to work on your PC you will have to

High-performance Javascript color gradient library powered by Rust + WebAssembly

colorgrad-js High-performance Javascript color gradient library powered by Rust + WebAssembly. No dependencies. Faster than d3-scale, chroma-js, culor

Tiny color conversion library for TUI application builders
Tiny color conversion library for TUI application builders

Definition of ANSI, RGB and HSL color types and all the conversions between them. There are many other color conversion crates. This one may be useful

A command line tool for playing with color gradients
A command line tool for playing with color gradients

gradient A command-line tool for playing with color gradients. Features Lots of preset gradients. Custom gradient. Read gradients from SVG & GIMP grad

dye is a tool to easily color text in shell.
dye is a tool to easily color text in shell.

Dye dye is a tool to easily color text in shell. Usage See the gif below to see these commands in action. echo $(dye --red WARN) This tool will knock

Owner
cx33
人生はとても短いです.
cx33
Parse hex colors to tui::style::Color

Color -> Tui Parse hex colors to tui rgb colors #c3f111 -> Color::Rgb(195,241,17) Note that the indexed colors are NOT HEX #142 -> Color::Indexed(142)

Uttarayan Mondal 1 Nov 8, 2021
Shared execution environment for constructing 3D virtual spaces from the inside.

Hearth Hearth is a shared, always-on execution environment for constructing 3D virtual spaces from the inside. Come join our Discord server! The Histo

null 6 Jan 31, 2023
Command-Line program that takes images and produces the copy of the image with a thin frame and palette made of the 10 most frequent colors.

paleatra v.0.0.1 Command-Line program that takes an image and produces the copy of the image with a thin frame and palette made of the 10 most frequen

Beka Modebadze 24 Dec 29, 2022
Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal.

Vari Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal. Like Rich library for Python. Väri means "co

azur 13 Nov 2, 2022
A CLI utility installed as "ansi" to quickly get ANSI escape sequences. Supports the most basic ones, like colors and styles as bold or italic.

'ansi' - a CLI utility to quickly get ANSI escape codes This Rust project called ansi-escape-sequences-cli provides an executable called ansi which ca

Philipp Schuster 5 Jul 28, 2022
Not the fastest terminal colors library. Don't even ask about size.

TROLOLORS Not the fastest terminal colors library. Don't even ask about size. Why? Don't even try to use it. But maybe you need to say to your boss th

Dmitriy Kovalenko 15 Oct 27, 2021
Customize window border colors :3

cute-borders Makes focused and unfocused window borders have a different border color, configurable per program. Windows 11 only. Preview Installing D

Elaina 6 Aug 16, 2023
Blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes.

lutgen-rs A blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes. Theme any image to your dekstop colorsc

null 12 Jun 16, 2023
An abstract, safe, and concise color conversion library for rust nightly This requires the feature adt_const_params

colortypes A type safe color conversion library This crate provides many methods for converting between color types. Everything is implemented abstrac

Jacob 13 Dec 7, 2022
`ls` alternative with useful info and a splash of color 🎨

?? Natls ?? Why Natls? Showing file permissions Showing file size Showing the date that the file was modified last Showing the user that the file belo

Will 1.2k Dec 19, 2022