5 unstable releases
|0.8.2||Feb 10, 2021|
|0.8.1||Apr 29, 2020|
|0.8.0||Apr 8, 2020|
|0.7.0||Feb 22, 2020|
|0.1.0||Feb 21, 2020|
#16 in Images
1,028 downloads per month
Used in 8 crates (4 directly)
This crate provides a color system for use in the
bracket-terminal system. It is part of the overall
bracket-color, include the following in your
[dependencies] bracket-color = "0.8.2"
The basic structure is
RGB, which represents a color as red/green/blue components. You can construct a color in a number of ways:
new()provides a black (all zeroes) entry.
from_f32takes three floats, from
1.0as a starting point.
from_u8takes there bytes, from
namedtakes a tuple of floats, with a LOT of predefined colors available. (e.g.
from_hextakes an HTML/CSS style hex number and converts it (e.g.
You can also convert RGB structures:
- Add, subtract, multiply and divide operations are supported both on a single float and against another RGB structure.
to_hsvmakes a Hue-Saturation-Value color.
to_greyscaleuses a standard grayscale operation to make a greyscale approximation of a color.
desaturatemakes a better greyscale conversion by converting to HSV and lowering the saturation.
lerplets you smoothly transition between two colors, in RGB space.
The HSV system provides color support in the HSV space. You can construct an HSV color as follows:
new()makes an all-zero HSV color.
from_f32lets you specify HSV as floats.
RGB::to_hsvconverts an RGB color into an HSV color.
You can also go back to RGB with
ColorPair is simply a helper structure holding both a foreground and a background.
Everything is exported via the
- If you enable the
serdefeature flag, the RGB, HSV and ColorPair structures are derived as
rexfeature flag enables RexPaint support.
palettefeature flag enables a static (thread-safe) palette map, linking named colors to colors. It's empty by default (the
add_named_colors_to_paletteadds all of the constant named colors for you, in lower case).
There are a few examples to help get you going. They use
crossterm for terminal output. You may run the examples with
cargo run --example <name>.
lerpis a simple color lerp.
lerpitis an iterator-based lerp.
lerpit_hsvis an HSV lerp.
named_colorsdemonstrates how to access named colors.
shades_of_greydemonstrates greyscale and desaturate functions.
colorsdemonstrates various ways to acquire colors.