pub struct Color<T, W = D65>where
T: FloatNumber,{ /* private fields */ }Expand description
The color representation.
ยงType Parameters
T- The floating point type.W- The white point type.
ยงExamples
use std::str::FromStr;
use auto_palette::color::Color;
let color: Color<f32> = Color::from_str("#2c7de7").unwrap();
assert!(color.is_light());
assert!(color.lightness() - 52.917 < 1e-3);
assert!(color.chroma() - 61.981 < 1e-3);
assert!(color.hue().to_degrees() - 282.662 < 1e-3);
let rgb = color.to_rgb();
assert_eq!(format!("{}", rgb), "RGB(44, 125, 231)");
let hsl = color.to_hsl();
assert_eq!(format!("{}", hsl), "HSL(214.01, 0.80, 0.54)");
let lab = color.to_lab();
assert_eq!(format!("{}", lab), "Lab(52.92, 13.59, -60.47)");Implementationsยง
Sourceยงimpl<T, W> Color<T, W>where
T: FloatNumber,
W: WhitePoint,
impl<T, W> Color<T, W>where
T: FloatNumber,
W: WhitePoint,
Sourcepub fn delta_e(&self, other: &Self) -> T
pub fn delta_e(&self, other: &Self) -> T
Calculates the delta E76 value between this color and another color.
ยงArguments
other- The other color to compare against.
ยงReturns
The delta E76 value, which is a measure of the difference between two colors.
ยงNote
This method uses the CIE76 formula, which is a simple Euclidean distance in the Lab* color space. Color difference CIE76 - Wikipedia
Sourcepub fn hue(&self) -> Hue<T>
pub fn hue(&self) -> Hue<T>
Returns the hue of this color. The hue is the angle of the vector in the ab plane.
ยงReturns
The hue of this color.
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Converts this color to a hexadecimal string.
ยงReturns
The hexadecimal string representation of this color.
Sourcepub fn to_ansi256(&self) -> Ansi256
pub fn to_ansi256(&self) -> Ansi256
Sourcepub fn to_rgb_int(&self) -> u32
pub fn to_rgb_int(&self) -> u32
Converts this color to a 32-bit integer representation in RGB.
ยงReturns
The converted RGB integer representation.
Sourcepub fn to_rgba_int(&self, alpha: u8) -> u32
pub fn to_rgba_int(&self, alpha: u8) -> u32
Trait Implementationsยง
Sourceยงimpl<T> Default for Color<T>where
T: FloatNumber,
impl<T> Default for Color<T>where
T: FloatNumber,
Sourceยงimpl<T> Display for Color<T>where
T: FloatNumber,
impl<T> Display for Color<T>where
T: FloatNumber,
Sourceยงimpl<T> FromStr for Color<T>where
T: FloatNumber,
impl<T> FromStr for Color<T>where
T: FloatNumber,
impl<T, W: Copy> Copy for Color<T, W>where
T: FloatNumber + Copy,
impl<T, W: Eq> Eq for Color<T, W>where
T: FloatNumber + Eq,
impl<T, W> StructuralPartialEq for Color<T, W>where
T: FloatNumber,
Auto Trait Implementationsยง
impl<T, W> Freeze for Color<T, W>where
T: Freeze,
impl<T, W> RefUnwindSafe for Color<T, W>where
T: RefUnwindSafe,
W: RefUnwindSafe,
impl<T, W> Send for Color<T, W>
impl<T, W> Sync for Color<T, W>
impl<T, W> Unpin for Color<T, W>
impl<T, W> UnwindSafe for Color<T, W>where
T: UnwindSafe,
W: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more