Crate glm_color [−] [src]
A simple crate for manipulating and generating color values. It is an
extension to the glm
crate.
glm_color
treats color values as numbers, instead of somthing that can be
used in rendering directly. So things like data format, order of channels,
and even alpha channel, are not handled by this library.
The only interesting part of this crate is functions in Rgb
and Hsv
color spaces that produce colors procedurally. The design of these functions
are based on Wikipedia page Color Theory
and this blog.
Example
Generating colors
use glm::*; use glm::ext::tau; use glm_color::*; // constant color values. let mut red = RED; // with constructors. red = Rgb::new(1., 0., 0.); red = rgb(255, 0, 0); // from other color spaces. red = hsv(tau(), 1., 1.).to_rgb(); red = ycbcr(1., 0., 0.5).to_rgb(); // randomly. let rnd = Rgb::rand(); let rnd_hsv = Hsv::rand(); // procedurally. let blues = from_rgb::<Hsv>(BLUE).analogs(5, radians(30.)); let yellows: Vec<Hsv> = blues.iter().map(|clr| -> Hsv { clr.complement() }).collect(); let darker_red = from_rgb::<Hsv>(RED).shade(0.3);
Manipulating colors
use glm_color::*; // Linear RGB color space supports some arithmetics. let yellow = RED + GREEN; let white = yellow + BLUE; assert_eq!(white, WHITE);
Converting colors
use glm::*; use glm_color::*; let rgb = RED; // All color spaces can be converted to and from the linear RGB color space. let hsv = Hsv::from_rgb(rgb); let mut red = hsv.to_rgb(); assert!(is_close_to(&rgb, &red, 0.000001)); let ybr: YCbCr = from_rgb(rgb); red = to_rgb(&ybr); let srgb = Srgb::from_rgb(rgb);
Reexports
pub use rgb::Rgb; |
pub use rgb::rgb; |
pub use rgb::gray; |
pub use rgb::grey; |
pub use rgb::consts::*; |
pub use hsv::Hsv; |
pub use hsv::hsv; |
pub use ycbcr::YCbCr; |
pub use ycbcr::ycbcr; |
pub use srgb::Srgb; |
pub use srgb::srgb; |
Modules
hsv | |
rgb | |
srgb | |
ycbcr |
Traits
ColorSpace |
|
Functions
from_rgb |
Converts |
to_rgb |
Converts |