pub struct Rgb { /* private fields */ }
Expand description
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.
use colorsys::{Rgb, Hsl, prelude::*};
let mut rgb1 = Rgb::from((100.0, 255.0, 17.0));
let green = rgb1.green();
rgb1.set_red(108.3);
let mut hsl: Hsl = rgb1.into();
hsl.saturate( SaturationInSpace::Hsl(-57.901) );
let mut rgb2 = Rgb::from(&hsl);
let rgb2tuple: (f64,f64,f64) = rgb2.as_ref().into();
rgb2 += Rgb::from_hex_str("#35f15b").unwrap();;
rgb2.set_green(-150.0);
assert_eq!(rgb2.green(), 0.0);
rgb2.lighten(-13.123);
rgb2.grayscale_simple();
let css_string = rgb2.to_css_string();
assert_eq!(css_string, "rgb(55,55,55)");
👎Deprecated since 0.7.0: Please use red
instead
👎Deprecated since 0.7.0: Please use green
instead
👎Deprecated since 0.7.0: Please use blue
instead
Returns a String that can be used in CSS.
use colorsys::{Rgb};
let rgb = Rgb::from([55.0,31.1, 201.9]);
assert_eq!(rgb.to_css_string(), "rgb(55,31,202)");
Returns an iterator over three color units and the possibly alpha value.
Returns an RGB representation with values converted to floar from 0.0 to 1.0
The resulting type after applying the +
operator.
The resulting type after applying the +
operator.
The resulting type after applying the +
operator.
Converts this type into a shared reference of the (usually inferred) input type.
Performs copy-assignment from
source
.
Read more
Lighten or darken color. amt is a percent with negative values - -100..100
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)" );
Saturate/desaturate color.
Value is percent: -100..100
.
You need specify in what color space you want to increase/decrease saturation.
increase/decrease color tone. Value is degree - -360..360
.
Brings color to a shade of gray. For more specific grayscale methods see Rgb.grayscale
Just inverts color
Formats the value using the given formatter.
Read more
Returns the “default value” for a type.
Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
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)");
Converts to this type from the input type.
Converts to this type from the input type.
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%)");
Converts to this type from the input type.
Converts to this type from the input type.
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)");
Converts to this type from the input type.
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%)");
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
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)");
Converts to this type from the input type.
Converts to this type from the input type.
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%)");
Converts to this type from the input type.
The associated error which can be returned from parsing.
Parses a string
s
to return a value of this type.
Read more
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
Converts this type into the (usually inferred) input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
This method tests for self
and other
values to be equal, and is used
by ==
.
This method tests for !=
. The default implementation is almost always
sufficient, and should not be overridden without very good reason.
The resulting type after applying the -
operator.
The resulting type after applying the -
operator.
The resulting type after applying the -
operator.
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Calls U::from(self)
.
That is, this conversion is whatever the implementation of
From<T> for U
chooses to do.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning.
Read more
Uses borrowed data to replace owned data, usually by cloning.
Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.