6 releases
| 0.8.7 | Oct 4, 2022 |
|---|---|
| 0.8.2 | Feb 10, 2021 |
| 0.8.1 | Apr 29, 2020 |
| 0.7.0 | Feb 22, 2020 |
| 0.1.0 | Feb 21, 2020 |
#574 in Images
12,836 downloads per month
Used in 12 crates
(5 directly)
135KB
3.5K
SLoC
bracket-color
This crate provides a color system for use in the bracket-terminal system. It is part of the overall bracket-lib system.
Using bracket-color
To obtain bracket-color, include the following in your Cargo.toml file:
[dependencies]
bracket-color = "~0.8"
RGB
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, from0.0to1.0as a starting point.from_u8takes there bytes, from0to255.namedtakes a tuple of floats, with a LOT of predefined colors available. (e.g.RGB::named(RED)).from_hextakes an HTML/CSS style hex number and converts it (e.g.RGB::from_hex("#aabbcc"))).
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.
HSV
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 to_rgb.
ColorPair
A ColorPair is simply a helper structure holding both a foreground and a background.
Exports
Everything is exported via the bracket_color::prelude namespace.
Feature Flags
- If you enable the
serdefeature flag, the RGB, HSV and ColorPair structures are derived asSerdeserializable/de-serializable. - The
rexfeature flag enables RexPaint support. - The
palettefeature flag enables a static (thread-safe) palette map, linking named colors to colors. It's empty by default (theadd_named_colors_to_paletteadds all of the constant named colors for you, in lower case). - If you enable the
bevyfeature, conversions between Bevy'sColortype and thebracket-colortypes are enabled.
Examples
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.
Dependencies
~0–22MB
~260K SLoC