Expand description
Color value
Fields
red: f64
Red component [0,1]
green: f64
Green component [0,1]
blue: f64
Blue component [0,1]
alpha: f64
Alpha component [0,1]
Implementations
sourceimpl Color
impl Color
sourcepub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Color
pub fn new(red: f64, green: f64, blue: f64, alpha: f64) -> Color
Create new color from components
use tint::Color;
let red = Color::new(1.0, 0.0, 0.0, 1.0);
let fushcia = Color::new(1.0, 0.0, 1.0, 1.0);
sourcepub fn from_rgb1(r: f64, g: f64, b: f64) -> Color
pub fn from_rgb1(r: f64, g: f64, b: f64) -> Color
Create new color from RGB components [0. .. 1.0], alpha value set to 1.0
let blue = Color::from_rgb1(0.0, 0.0, 1.0);
sourcepub fn from_rgb1v(rgb: &[f64]) -> Color
pub fn from_rgb1v(rgb: &[f64]) -> Color
Create new color from RGB f64 vector [0. .. 1.0], alpha value set to 1.0
let green = Color::from_rgb1v(&[0.0, 1.0, 0.0]);
sourcepub fn to_rgb1(&self) -> (f64, f64, f64)
pub fn to_rgb1(&self) -> (f64, f64, f64)
Convert Color to (f64,f64,f64)
let purple = Color::new(1.0, 0.0, 1.0, 1.0);
let rgb = purple.to_rgb1();
assert_eq!(rgb, (1.0, 0.0, 1.0));
sourcepub fn from_rgb255(red: u8, green: u8, blue: u8) -> Color
pub fn from_rgb255(red: u8, green: u8, blue: u8) -> Color
Create new Color from RGB [0 .. 255] alpha value set to 1.0
let purple = Color::from_rgb255(255, 0, 255);
sourcepub fn from_rgb255v(rgb: &[u8]) -> Color
pub fn from_rgb255v(rgb: &[u8]) -> Color
Create new Color from RGB u8 vector [0 .. 255] alpha value set to 1.0
let purple = Color::from_rgb255v(&[255, 0, 255]);
assert_eq!(purple.red, 1.0);
assert_eq!(purple.green, 0.0);
assert_eq!(purple.blue, 1.0);
sourcepub fn to_rgb255(&self) -> (u8, u8, u8)
pub fn to_rgb255(&self) -> (u8, u8, u8)
Convert color to (u8,u8,u8)
let purple = Color::new(1.0, 0.0, 1.0, 1.0);
assert_eq!(purple.to_rgb255(), (255,0,255));
sourcepub fn from_hex(hex: &str) -> Color
pub fn from_hex(hex: &str) -> Color
Create new Color from Hex String
let facade = Color::from_hex("#facade");
assert_eq!(facade.to_rgb255(), (250, 202, 222));
sourcepub fn to_hex(&self) -> String
pub fn to_hex(&self) -> String
Convert Color into Hex String
let coffee = Color::from_rgb255(192, 255, 238);
assert_eq!(coffee.to_hex(), "#c0ffee");
sourcepub fn name(name: &str) -> Option<Color>
pub fn name(name: &str) -> Option<Color>
Get Color from exiting named colors Colors are defined from w3c Basic and Extended colors and colors from the XKCD database if loaded
let chartreuse = Color::name("chartreuse");
assert_eq!(chartreuse, Some(Color::from_hex("7fff00")));
let olive_drab = Color::name("olivedrab").unwrap();
assert_eq!(olive_drab.to_rgb255(), (107,142,35));
tint::xkcd();
let butterscotch = Color::name("butterscotch").unwrap();
assert_eq!(butterscotch.to_hex(), "#fdb147");
let avocado = Color::name("avocado green").unwrap();
assert_eq!(avocado.to_rgb255(), (135, 169, 34));
Trait Implementations
sourceimpl<'a> From<&'a Vec<f32, Global>> for Color
impl<'a> From<&'a Vec<f32, Global>> for Color
Convert from a f32 Vec, red, green, blue, maybe alpha
This may fail
sourceimpl<'a> From<&'a Vec<f64, Global>> for Color
impl<'a> From<&'a Vec<f64, Global>> for Color
Convert from a f64 Vec, red, green, blue, maybe alpha
This may fail
sourceimpl From<Vec<f32, Global>> for Color
impl From<Vec<f32, Global>> for Color
Convert from a f32 Vec, red, green, blue, maybe alpha
This may fail
sourceimpl From<Vec<f64, Global>> for Color
impl From<Vec<f64, Global>> for Color
Convert from a f32 Vec, red, green, blue, maybe alpha
This may fail
impl Copy for Color
Auto Trait Implementations
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more