Struct colorsys::Rgb [−][src]
The RGB color model.
Has red, green, blue and optional alpha
channel fields.
Red, green, blue values are stored between 0.0 and 255.0, alpha is between 0.0 and 1.0.
If inputted or received values are exceeds the allowed value, or is less than zero
it will be equalize to limit.
Example
use colorsys::{Rgb, Hsl, prelude::*}; let mut rgb1 = Rgb::from((100.0, 255.0, 17.0)); // Rgb { r: 100.0, g: 255.0, b: 17.0, a: None } let green = rgb1.green(); // 255.0 rgb1.set_red(108.3); // Rgb { r: 108.3, g: 255.0, b: 17.0, .. } let mut hsl: Hsl = rgb1.into(); // ~Hsl { h: 96.98, s: 100.0, l: 53.333, .. } hsl.saturate( SaturationInSpace::Hsl(-57.901) ); // ~Hsl { h: 96.98, s: 42.099, l: 53.333, .. } let mut rgb2 = Rgb::from(&hsl); // ~Rgb { r: 124.34, g: 186.1, b: 85.9, .. } let rgb2tuple: (f64,f64,f64) = rgb2.as_ref().into(); // (124.34, 186.1,85.9) rgb2 += Rgb::from_hex_str("#35f15b").unwrap();; // ~Rgb { r: 177.33, g: 255.0, b: 176.902, .. } rgb2.set_green(-150.0); assert_eq!(rgb2.green(), 0.0); rgb2.lighten(-13.123); // ~Rgb { r: 110.41, g: 0.0, b: 110.1, .. } rgb2.grayscale_simple(); // ~Rgb { r: 55.2, g: 55.2, b: 55.2, .. } let css_string = rgb2.to_css_string(); assert_eq!(css_string, "rgb(55,55,55)");
Implementations
impl Rgb
[src]
pub fn new(r: f64, g: f64, b: f64, a: Option<f64>) -> Rgb
[src]
pub fn from_hex_str(s: &str) -> Result<Rgb, ParseError>
[src]
pub fn to_hex_string(&self) -> String
[src]
pub fn red(&self) -> f64
[src]
pub fn green(&self) -> f64
[src]
pub fn blue(&self) -> f64
[src]
pub fn get_red(&self) -> f64
[src]
Please use red
instead
pub fn get_green(&self) -> f64
[src]
Please use green
instead
pub fn get_blue(&self) -> f64
[src]
Please use blue
instead
pub fn set_red(&mut self, val: f64)
[src]
pub fn set_green(&mut self, val: f64)
[src]
pub fn set_blue(&mut self, val: f64)
[src]
pub fn to_css_string(&self) -> String
[src]
Returns a String that can be used in CSS.
Example
use colorsys::{Rgb}; let rgb = Rgb::from([55.0,31.1, 201.9]); assert_eq!(rgb.to_css_string(), "rgb(55,31,202)");
pub fn grayscale(&mut self, method: GrayScaleMethod)
[src]
pub fn iter(&self) -> ColorUnitsIter
[src]
Returns an iterator over three color units and the possibly alpha value.
pub fn as_ratio(&self) -> RgbRatio
[src]
Returns an RGB representation with values converted to floar from 0.0 to 1.0
Trait Implementations
impl<'a> Add<&'a Rgb> for &'a Rgb
[src]
type Output = Rgb
The resulting type after applying the +
operator.
fn add(self, rhs: &Rgb) -> Rgb
[src]
impl<'a> Add<&'a mut Rgb> for &'a mut Rgb
[src]
type Output = Rgb
The resulting type after applying the +
operator.
fn add(self, rhs: &'a mut Rgb) -> Rgb
[src]
impl Add<Rgb> for Rgb
[src]
type Output = Rgb
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
impl AddAssign<Rgb> for Rgb
[src]
fn add_assign(&mut self, rhs: Self)
[src]
impl ApproxEq<Hsl> for Rgb
[src]
fn approx_eq(&self, hsl: &Hsl) -> bool
[src]
fn approx_eq_clarify(&self, hsl: &Hsl, precision: f64) -> bool
[src]
impl ApproxEq<Rgb> for Hsl
[src]
fn approx_eq(&self, rgb: &Rgb) -> bool
[src]
fn approx_eq_clarify(&self, rgb: &Rgb, precision: f64) -> bool
[src]
impl AsRef<Rgb> for Rgb
[src]
impl Clone for Rgb
[src]
impl ColorTransform for Rgb
[src]
fn lighten(&mut self, amt: f64)
[src]
Lighten or darken color. amt is a percent with negative values - -100..100
Example
use colorsys::{Rgb,ColorTransform, ColorTuple}; let tuple = (30.0, 108.0, 77.0); let mut rgb = Rgb::from(&tuple); rgb.lighten(20.0); assert_eq!(rgb.to_css_string(), "rgb(52,188,134)" ); rgb.lighten(-20.0); assert_eq!(rgb.to_css_string(), "rgb(30,108,77)" ); rgb.lighten(-20.0); assert_eq!(rgb.to_css_string(), "rgb(8,28,20)" ); rgb.lighten(301.123); assert_eq!(rgb.to_css_string(), "rgb(255,255,255)" );
fn saturate(&mut self, sat: SaturationInSpace)
[src]
fn adjust_hue(&mut self, hue: f64)
[src]
fn grayscale_simple(&mut self)
[src]
fn invert(&mut self)
[src]
impl Debug for Rgb
[src]
impl Default for Rgb
[src]
impl From<&'_ [f32; 3]> for Rgb
[src]
impl From<&'_ [f32; 4]> for Rgb
[src]
impl From<&'_ [f64; 3]> for Rgb
[src]
impl From<&'_ [f64; 4]> for Rgb
[src]
impl From<&'_ [i16; 3]> for Rgb
[src]
impl From<&'_ [i32; 3]> for Rgb
[src]
impl From<&'_ [i64; 3]> for Rgb
[src]
impl From<&'_ [u16; 3]> for Rgb
[src]
impl From<&'_ [u32; 3]> for Rgb
[src]
impl From<&'_ [u64; 3]> for Rgb
[src]
impl From<&'_ [u8; 3]> for Rgb
[src]
impl From<&'_ (f32, f32, f32, f32)> for Rgb
[src]
impl From<&'_ (f32, f32, f32)> for Rgb
[src]
impl From<&'_ (f64, f64, f64, f64)> for Rgb
[src]
impl From<&'_ (f64, f64, f64)> for Rgb
[src]
impl From<&'_ (i16, i16, i16)> for Rgb
[src]
impl From<&'_ (i32, i32, i32)> for Rgb
[src]
impl From<&'_ (i64, i64, i64)> for Rgb
[src]
impl From<&'_ (u16, u16, u16)> for Rgb
[src]
impl From<&'_ (u32, u32, u32)> for Rgb
[src]
impl From<&'_ (u64, u64, u64)> for Rgb
[src]
impl From<&'_ (u8, u8, u8)> for Rgb
[src]
impl From<&'_ Cmyk> for Rgb
[src]
impl From<&'_ Hsl> for Rgb
[src]
fn from(hsl: &Hsl) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let hsl = Hsl::from(&(48.0, 70.0, 50.0)); let rgb: Rgb = Rgb::from(&hsl); assert_eq!(rgb.to_css_string(), "rgb(217,181,38)");
impl From<&'_ Rgb> for Hsl
[src]
fn from(rgb: &Rgb) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let rgb = Rgb::from(&(215.0, 231.0, 236.0)); let hsl = Hsl::from(&rgb); assert_eq!(hsl.to_css_string(), "hsl(194,36%,88%)");
impl From<&'_ Rgb> for Cmyk
[src]
impl From<&'_ RgbRatio> for Rgb
[src]
impl From<&'_ mut Cmyk> for Rgb
[src]
impl From<&'_ mut Hsl> for Rgb
[src]
fn from(hsl: &mut Hsl) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let mut hsl = Hsl::from(&(359.0, 33.0, 77.0)); let rgb_string = Rgb::from(&mut hsl).to_css_string(); assert_eq!(rgb_string, "rgb(216,177,178)");
impl From<&'_ mut Rgb> for Hsl
[src]
fn from(rgb: &mut Rgb) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let mut rgb = Rgb::from(&(0.0, 0.0, 0.0)); let hsl_string = Hsl::from(&mut rgb).to_css_string(); assert_eq!(hsl_string, "hsl(0,0%,0%)");
impl From<&'_ mut Rgb> for Cmyk
[src]
impl From<&'_ mut RgbRatio> for Rgb
[src]
impl From<[f32; 3]> for Rgb
[src]
impl From<[f32; 4]> for Rgb
[src]
impl From<[f64; 3]> for Rgb
[src]
impl From<[f64; 4]> for Rgb
[src]
impl From<[i16; 3]> for Rgb
[src]
impl From<[i32; 3]> for Rgb
[src]
impl From<[i64; 3]> for Rgb
[src]
impl From<[u16; 3]> for Rgb
[src]
impl From<[u32; 3]> for Rgb
[src]
impl From<[u64; 3]> for Rgb
[src]
impl From<[u8; 3]> for Rgb
[src]
impl From<(f32, f32, f32, f32)> for Rgb
[src]
impl From<(f32, f32, f32)> for Rgb
[src]
impl From<(f64, f64, f64, f64)> for Rgb
[src]
impl From<(f64, f64, f64)> for Rgb
[src]
impl From<(i16, i16, i16)> for Rgb
[src]
impl From<(i32, i32, i32)> for Rgb
[src]
impl From<(i64, i64, i64)> for Rgb
[src]
impl From<(u16, u16, u16)> for Rgb
[src]
impl From<(u32, u32, u32)> for Rgb
[src]
impl From<(u64, u64, u64)> for Rgb
[src]
impl From<(u8, u8, u8)> for Rgb
[src]
impl From<Cmyk> for Rgb
[src]
impl From<Hsl> for Rgb
[src]
fn from(hsl: Hsl) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let hsl = Hsl::from(&(192.0, 67.0, 28.0)); let rgb_string = Rgb::from(hsl).to_css_string(); assert_eq!(rgb_string, "rgb(24,100,119)");
impl From<Rgb> for Hsl
[src]
fn from(rgb: Rgb) -> Self
[src]
Example
use colorsys::{Rgb,Hsl,prelude::*}; let rgb = Rgb::from(&(255.0, 255.0, 255.0)); let hsl_string = Hsl::from(rgb).to_css_string(); assert_eq!(hsl_string, "hsl(0,0%,100%)");
impl From<Rgb> for Cmyk
[src]
impl From<RgbRatio> for Rgb
[src]
impl FromStr for Rgb
[src]
type Err = ParseError
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<Rgb, ParseError>
[src]
impl<'a> Into<[f32; 3]> for &'a Rgb
[src]
impl<'a> Into<[f32; 3]> for &'a mut Rgb
[src]
impl Into<[f32; 3]> for Rgb
[src]
impl<'a> Into<[f32; 4]> for &'a Rgb
[src]
impl<'a> Into<[f32; 4]> for &'a mut Rgb
[src]
impl Into<[f32; 4]> for Rgb
[src]
impl<'a> Into<[f64; 3]> for &'a Rgb
[src]
impl<'a> Into<[f64; 3]> for &'a mut Rgb
[src]
impl Into<[f64; 3]> for Rgb
[src]
impl<'a> Into<[f64; 4]> for &'a Rgb
[src]
impl<'a> Into<[f64; 4]> for &'a mut Rgb
[src]
impl Into<[f64; 4]> for Rgb
[src]
impl<'a> Into<[i16; 3]> for &'a Rgb
[src]
impl<'a> Into<[i16; 3]> for &'a mut Rgb
[src]
impl Into<[i16; 3]> for Rgb
[src]
impl<'a> Into<[i32; 3]> for &'a Rgb
[src]
impl<'a> Into<[i32; 3]> for &'a mut Rgb
[src]
impl Into<[i32; 3]> for Rgb
[src]
impl<'a> Into<[i64; 3]> for &'a Rgb
[src]
impl<'a> Into<[i64; 3]> for &'a mut Rgb
[src]
impl Into<[i64; 3]> for Rgb
[src]
impl<'a> Into<[u16; 3]> for &'a Rgb
[src]
impl<'a> Into<[u16; 3]> for &'a mut Rgb
[src]
impl Into<[u16; 3]> for Rgb
[src]
impl<'a> Into<[u32; 3]> for &'a Rgb
[src]
impl<'a> Into<[u32; 3]> for &'a mut Rgb
[src]
impl Into<[u32; 3]> for Rgb
[src]
impl<'a> Into<[u64; 3]> for &'a Rgb
[src]
impl<'a> Into<[u64; 3]> for &'a mut Rgb
[src]
impl Into<[u64; 3]> for Rgb
[src]
impl<'a> Into<[u8; 3]> for &'a Rgb
[src]
impl<'a> Into<[u8; 3]> for &'a mut Rgb
[src]
impl Into<[u8; 3]> for Rgb
[src]
impl<'a> Into<(f32, f32, f32, f32)> for &'a Rgb
[src]
impl<'a> Into<(f32, f32, f32, f32)> for &'a mut Rgb
[src]
impl Into<(f32, f32, f32, f32)> for Rgb
[src]
impl<'a> Into<(f32, f32, f32)> for &'a Rgb
[src]
impl<'a> Into<(f32, f32, f32)> for &'a mut Rgb
[src]
impl Into<(f32, f32, f32)> for Rgb
[src]
impl<'a> Into<(f64, f64, f64, f64)> for &'a Rgb
[src]
impl<'a> Into<(f64, f64, f64, f64)> for &'a mut Rgb
[src]
impl Into<(f64, f64, f64, f64)> for Rgb
[src]
impl<'a> Into<(f64, f64, f64)> for &'a Rgb
[src]
impl<'a> Into<(f64, f64, f64)> for &'a mut Rgb
[src]
impl Into<(f64, f64, f64)> for Rgb
[src]
impl<'a> Into<(i16, i16, i16)> for &'a Rgb
[src]
impl<'a> Into<(i16, i16, i16)> for &'a mut Rgb
[src]
impl Into<(i16, i16, i16)> for Rgb
[src]
impl<'a> Into<(i32, i32, i32)> for &'a Rgb
[src]
impl<'a> Into<(i32, i32, i32)> for &'a mut Rgb
[src]
impl Into<(i32, i32, i32)> for Rgb
[src]
impl<'a> Into<(i64, i64, i64)> for &'a Rgb
[src]
impl<'a> Into<(i64, i64, i64)> for &'a mut Rgb
[src]
impl Into<(i64, i64, i64)> for Rgb
[src]
impl<'a> Into<(u16, u16, u16)> for &'a Rgb
[src]
impl<'a> Into<(u16, u16, u16)> for &'a mut Rgb
[src]
impl Into<(u16, u16, u16)> for Rgb
[src]
impl<'a> Into<(u32, u32, u32)> for &'a Rgb
[src]
impl<'a> Into<(u32, u32, u32)> for &'a mut Rgb
[src]
impl Into<(u32, u32, u32)> for Rgb
[src]
impl<'a> Into<(u64, u64, u64)> for &'a Rgb
[src]
impl<'a> Into<(u64, u64, u64)> for &'a mut Rgb
[src]
impl Into<(u64, u64, u64)> for Rgb
[src]
impl<'a> Into<(u8, u8, u8)> for &'a Rgb
[src]
impl<'a> Into<(u8, u8, u8)> for &'a mut Rgb
[src]
impl Into<(u8, u8, u8)> for Rgb
[src]
impl<'a> Into<RgbRatio> for &'a Rgb
[src]
impl<'a> Into<RgbRatio> for &'a mut Rgb
[src]
impl Into<RgbRatio> for Rgb
[src]
impl<'a> IntoIterator for &'a Rgb
[src]
type Item = f64
The type of the elements being iterated over.
type IntoIter = ColorUnitsIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> ColorUnitsIter
[src]
impl IntoIterator for Rgb
[src]
type Item = f64
The type of the elements being iterated over.
type IntoIter = ColorUnitsIter
Which kind of iterator are we turning this into?
fn into_iter(self) -> ColorUnitsIter
[src]
impl PartialEq<Rgb> for Rgb
[src]
impl StructuralPartialEq for Rgb
[src]
impl<'a> Sub<&'a Rgb> for &'a Rgb
[src]
type Output = Rgb
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Rgb
[src]
impl<'a> Sub<&'a mut Rgb> for &'a mut Rgb
[src]
type Output = Rgb
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Rgb
[src]
impl Sub<Rgb> for Rgb
[src]
type Output = Rgb
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
impl SubAssign<Rgb> for Rgb
[src]
fn sub_assign(&mut self, rhs: Self)
[src]
Auto Trait Implementations
impl RefUnwindSafe for Rgb
[src]
impl Send for Rgb
[src]
impl Sync for Rgb
[src]
impl Unpin for Rgb
[src]
impl UnwindSafe for Rgb
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,