Struct pix_engine::color::Color
source · [−]pub struct Color { /* private fields */ }Expand description
A color represented with a Mode.
Implementations
sourceimpl Color
impl Color
pub const ALICE_BLUE: Self = Self::rgb(0xF0, 0xF8, 0xFF)
pub const ANTIQUE_WHITE: Self = Self::rgb(0xFA, 0xEB, 0xD7)
pub const AQUA: Self = Self::rgb(0x0, 0xFF, 0xFF)
pub const AQUA_MARINE: Self = Self::rgb(0x7F, 0xFF, 0xD4)
pub const AZURE: Self = Self::rgb(0xF0, 0xFF, 0xFF)
pub const BEIGE: Self = Self::rgb(0xF5, 0xF5, 0xDC)
pub const BISQUE: Self = Self::rgb(0xFF, 0xE4, 0xC4)
pub const BLACK: Self = Self::rgb(0x0, 0x0, 0x0)
pub const BLANCHE_DALMOND: Self = Self::rgb(0xFF, 0xEB, 0xCD)
pub const BLUE: Self = Self::rgb(0x0, 0x0, 0xFF)
pub const BLUE_VIOLET: Self = Self::rgb(0x8A, 0x2B, 0xE2)
pub const BROWN: Self = Self::rgb(0xA5, 0x2A, 0x2A)
pub const BURLY_WOOD: Self = Self::rgb(0xDE, 0xB8, 0x87)
pub const CADET_BLUE: Self = Self::rgb(0x5F, 0x9E, 0xA0)
pub const CHARTREUSE: Self = Self::rgb(0x7F, 0xFF, 0x0)
pub const CHOCOLATE: Self = Self::rgb(0xD2, 0x69, 0x1E)
pub const CORAL: Self = Self::rgb(0xFF, 0x7F, 0x50)
pub const CORNFLOWER_BLUE: Self = Self::rgb(0x64, 0x95, 0xED)
pub const CORN_SILK: Self = Self::rgb(0xFF, 0xF8, 0xDC)
pub const CRIMSON: Self = Self::rgb(0xDC, 0x14, 0x3C)
pub const CYAN: Self = Self::rgb(0x0, 0xFF, 0xFF)
pub const DARK_BLUE: Self = Self::rgb(0x0, 0x0, 0x8B)
pub const DARK_CYAN: Self = Self::rgb(0x0, 0x8B, 0x8B)
pub const DARK_GOLDENROD: Self = Self::rgb(0xB8, 0x86, 0xB)
pub const DARK_GRAY: Self = Self::rgb(0xA9, 0xA9, 0xA9)
pub const DARK_GREEN: Self = Self::rgb(0x0, 0x64, 0x0)
pub const DARK_GREY: Self = Self::rgb(0xA9, 0xA9, 0xA9)
pub const DARK_KHAKI: Self = Self::rgb(0xBD, 0xB7, 0x6B)
pub const DARK_MAGENTA: Self = Self::rgb(0x8B, 0x0, 0x8B)
pub const DARK_OLIVE_GREEN: Self = Self::rgb(0x55, 0x6B, 0x2F)
pub const DARK_ORANGE: Self = Self::rgb(0xFF, 0x8C, 0x0)
pub const DARK_ORCHID: Self = Self::rgb(0x99, 0x32, 0xCC)
pub const DARK_RED: Self = Self::rgb(0x8B, 0x0, 0x0)
pub const DARK_SALMON: Self = Self::rgb(0xE9, 0x96, 0x7A)
pub const DARK_SEA_GREEN: Self = Self::rgb(0x8F, 0xBC, 0x8F)
pub const DARK_SLATE_BLUE: Self = Self::rgb(0x48, 0x3D, 0x8B)
pub const DARK_SLATE_GRAY: Self = Self::rgb(0x2F, 0x4F, 0x4F)
pub const DARK_SLATE_GREY: Self = Self::rgb(0x2F, 0x4F, 0x4F)
pub const DARK_TURQUOISE: Self = Self::rgb(0x0, 0xCE, 0xD1)
pub const DARK_VIOLET: Self = Self::rgb(0x94, 0x0, 0xD3)
pub const DEEP_PINK: Self = Self::rgb(0xFF, 0x14, 0x93)
pub const DEEP_SKY_BLUE: Self = Self::rgb(0x0, 0xBF, 0xFF)
pub const DIM_GRAY: Self = Self::rgb(0x69, 0x69, 0x69)
pub const DIM_GREY: Self = Self::rgb(0x69, 0x69, 0x69)
pub const DODGER_BLUE: Self = Self::rgb(0x1E, 0x90, 0xFF)
pub const FIRE_BRICK: Self = Self::rgb(0xB2, 0x22, 0x22)
pub const FLORAL_WHITE: Self = Self::rgb(0xFF, 0xFA, 0xF0)
pub const FOREST_GREEN: Self = Self::rgb(0x22, 0x8B, 0x22)
pub const FUCHSIA: Self = Self::rgb(0xFF, 0x0, 0xFF)
pub const GAINSBORO: Self = Self::rgb(0xDC, 0xDC, 0xDC)
pub const GHOST_WHITE: Self = Self::rgb(0xF8, 0xF8, 0xFF)
pub const GOLD: Self = Self::rgb(0xFF, 0xD7, 0x0)
pub const GOLDENROD: Self = Self::rgb(0xDA, 0xA5, 0x20)
pub const GRAY: Self = Self::rgb(0x80, 0x80, 0x80)
pub const GREEN: Self = Self::rgb(0x0, 0x80, 0x0)
pub const GREEN_YELLOW: Self = Self::rgb(0xAD, 0xFF, 0x2F)
pub const GREY: Self = Self::rgb(0x80, 0x80, 0x80)
pub const HONEYDEW: Self = Self::rgb(0xF0, 0xFF, 0xF0)
pub const HOTOINK: Self = Self::rgb(0xFF, 0x69, 0xB4)
pub const INDIAN_RED: Self = Self::rgb(0xCD, 0x5C, 0x5C)
pub const INDIGO: Self = Self::rgb(0x4B, 0x0, 0x82)
pub const IVORY: Self = Self::rgb(0xFF, 0xFF, 0xF0)
pub const KHAKI: Self = Self::rgb(0xF0, 0xE6, 0x8C)
pub const LAVENDER: Self = Self::rgb(0xE6, 0xE6, 0xFA)
pub const LAVENDER_BLUSH: Self = Self::rgb(0xFF, 0xF0, 0xF5)
pub const LAWN_GREEN: Self = Self::rgb(0x7C, 0xFC, 0x0)
pub const LEMON_CHIFFON: Self = Self::rgb(0xFF, 0xFA, 0xCD)
pub const LIGHT_BLUE: Self = Self::rgb(0xAD, 0xD8, 0xE6)
pub const LIGHT_CORAL: Self = Self::rgb(0xF0, 0x80, 0x80)
pub const LIGHT_CYAN: Self = Self::rgb(0xE0, 0xFF, 0xFF)
pub const LIGHT_GOLDENROD_YELLOW: Self = Self::rgb(0xFA, 0xFA, 0xD2)
pub const LIGHT_GRAY: Self = Self::rgb(0xD3, 0xD3, 0xD3)
pub const LIGHT_GREEN: Self = Self::rgb(0x90, 0xEE, 0x90)
pub const LIGHT_GREY: Self = Self::rgb(0xD3, 0xD3, 0xD3)
pub const LIGHT_PINK: Self = Self::rgb(0xFF, 0xB6, 0xC1)
pub const LIGHT_SALMON: Self = Self::rgb(0xFF, 0xA0, 0x7A)
pub const LIGHT_SEA_GREEN: Self = Self::rgb(0x20, 0xB2, 0xAA)
pub const LIGHT_SKY_BLUE: Self = Self::rgb(0x87, 0xCE, 0xFA)
pub const LIGHT_SLATE_GRAY: Self = Self::rgb(0x77, 0x88, 0x99)
pub const LIGHT_SLATE_GREY: Self = Self::rgb(0x77, 0x88, 0x99)
pub const LIGHT_STEEL_BLUE: Self = Self::rgb(0xB0, 0xC4, 0xDE)
pub const LIGHT_YELLOW: Self = Self::rgb(0xFF, 0xFF, 0xE0)
pub const LIME: Self = Self::rgb(0x0, 0xFF, 0x0)
pub const LIME_GREEN: Self = Self::rgb(0x32, 0xCD, 0x32)
pub const LINEN: Self = Self::rgb(0xFA, 0xF0, 0xE6)
pub const MAGENTA: Self = Self::rgb(0xFF, 0x0, 0xFF)
pub const MAROON: Self = Self::rgb(0x80, 0x0, 0x0)
pub const MEDIUMAQUA_MARINE: Self = Self::rgb(0x66, 0xCD, 0xAA)
pub const MEDIUM_BLUE: Self = Self::rgb(0x0, 0x0, 0xCD)
pub const MEDIUM_ORCHID: Self = Self::rgb(0xBA, 0x55, 0xD3)
pub const MEDIUM_PURPLE: Self = Self::rgb(0x93, 0x70, 0xDB)
pub const MEDIUM_SEA_GREEN: Self = Self::rgb(0x3C, 0xB3, 0x71)
pub const MEDIUM_SLATE_BLUE: Self = Self::rgb(0x7B, 0x68, 0xEE)
pub const MEDIUM_SPRING_GREEN: Self = Self::rgb(0x0, 0xFA, 0x9A)
pub const MEDIUM_TURQUOISE: Self = Self::rgb(0x48, 0xD1, 0xCC)
pub const MEDIUM_VIOLET_RED: Self = Self::rgb(0xC7, 0x15, 0x85)
pub const MIDNIGHT_BLUE: Self = Self::rgb(0x19, 0x19, 0x70)
pub const MINT_CREAM: Self = Self::rgb(0xF5, 0xFF, 0xFA)
pub const MISTY_ROSE: Self = Self::rgb(0xFF, 0xE4, 0xE1)
pub const MOCCASIN: Self = Self::rgb(0xFF, 0xE4, 0xB5)
pub const NAVAJO_WHITE: Self = Self::rgb(0xFF, 0xDE, 0xAD)
pub const NAVY: Self = Self::rgb(0x0, 0x0, 0x80)
pub const OLD_LACE: Self = Self::rgb(0xFD, 0xF5, 0xE6)
pub const OLIVE: Self = Self::rgb(0x80, 0x80, 0x0)
pub const OLIVE_DRAB: Self = Self::rgb(0x6B, 0x8E, 0x23)
pub const ORANGE: Self = Self::rgb(0xFF, 0xA5, 0x0)
pub const ORANGE_RED: Self = Self::rgb(0xFF, 0x45, 0x0)
pub const ORCHID: Self = Self::rgb(0xDA, 0x70, 0xD6)
pub const PALE_GOLDENROD: Self = Self::rgb(0xEE, 0xE8, 0xAA)
pub const PALE_GREEN: Self = Self::rgb(0x98, 0xFB, 0x98)
pub const PALE_TURQUOISE: Self = Self::rgb(0xAF, 0xEE, 0xEE)
pub const PALE_VIOLET_RED: Self = Self::rgb(0xDB, 0x70, 0x93)
pub const PAPAYA_WHIP: Self = Self::rgb(0xFF, 0xEF, 0xD5)
pub const PEACH_PUFF: Self = Self::rgb(0xFF, 0xDA, 0xB9)
pub const PERU: Self = Self::rgb(0xCD, 0x85, 0x3F)
pub const PINK: Self = Self::rgb(0xFF, 0xC0, 0xCB)
pub const PLUM: Self = Self::rgb(0xDD, 0xA0, 0xDD)
pub const POWDER_BLUE: Self = Self::rgb(0xB0, 0xE0, 0xE6)
pub const PURPLE: Self = Self::rgb(0x80, 0x0, 0x80)
pub const REBECCA_PURPLE: Self = Self::rgb(0x66, 0x33, 0x99)
pub const RED: Self = Self::rgb(0xFF, 0x0, 0x0)
pub const ROSY_BROWN: Self = Self::rgb(0xBC, 0x8F, 0x8F)
pub const ROYAL_BLUE: Self = Self::rgb(0x41, 0x69, 0xE1)
pub const SADDLE_BROWN: Self = Self::rgb(0x8B, 0x45, 0x13)
pub const SALMON: Self = Self::rgb(0xFA, 0x80, 0x72)
pub const SANDY_BROWN: Self = Self::rgb(0xF4, 0xA4, 0x60)
pub const SEA_GREEN: Self = Self::rgb(0x2E, 0x8B, 0x57)
pub const SEA_SHELL: Self = Self::rgb(0xFF, 0xF5, 0xEE)
pub const SIENNA: Self = Self::rgb(0xA0, 0x52, 0x2D)
pub const SILVER: Self = Self::rgb(0xC0, 0xC0, 0xC0)
pub const SKY_BLUE: Self = Self::rgb(0x87, 0xCE, 0xEB)
pub const SLATE_BLUE: Self = Self::rgb(0x6A, 0x5A, 0xCD)
pub const SLATE_GRAY: Self = Self::rgb(0x70, 0x80, 0x90)
pub const SLATE_GREY: Self = Self::rgb(0x70, 0x80, 0x90)
pub const SNOW: Self = Self::rgb(0xFF, 0xFA, 0xFA)
pub const SPRING_GREEN: Self = Self::rgb(0x0, 0xFF, 0x7F)
pub const STEEL_BLUE: Self = Self::rgb(0x46, 0x82, 0xB4)
pub const TAN: Self = Self::rgb(0xD2, 0xB4, 0x8C)
pub const TEAL: Self = Self::rgb(0x0, 0x80, 0x80)
pub const THISTLE: Self = Self::rgb(0xD8, 0xBF, 0xD8)
pub const TOMATO: Self = Self::rgb(0xFF, 0x63, 0x47)
pub const TRANSPARENT: Self = Self::rgba(0x0, 0x0, 0x0, 0x0)
pub const TURQUOISE: Self = Self::rgb(0x40, 0xE0, 0xD0)
pub const VIOLET: Self = Self::rgb(0xEE, 0x82, 0xEE)
pub const WHEAT: Self = Self::rgb(0xF5, 0xDE, 0xB3)
pub const WHITE: Self = Self::rgb(0xFF, 0xFF, 0xFF)
pub const WHITE_SMOKE: Self = Self::rgb(0xF5, 0xF5, 0xF5)
pub const YELLOW: Self = Self::rgb(0xFF, 0xFF, 0x0)
pub const YELLOW_GREEN: Self = Self::rgb(0x9A, 0xCD, 0x32)
sourceimpl Color
impl Color
sourcepub fn from_slice<T, S>(mode: ColorMode, slice: S) -> PixResult<Self> where
T: Copy + Into<f64>,
S: AsRef<[T]>,
pub fn from_slice<T, S>(mode: ColorMode, slice: S) -> PixResult<Self> where
T: Copy + Into<f64>,
S: AsRef<[T]>,
Constructs a Color from a slice of 1-4 values. The number of values
provided alter how they are interpreted similar to the color!, rgb!, hsb!, and
hsl! macros.
Errors
If the slice is empty or has more than 4 values, an error is returned.
Examples
let vals: Vec<f64> = vec![128.0, 64.0, 0.0];
let c = Color::from_slice(ColorMode::Rgb, &vals)?; // RGB Vec
assert_eq!(c.channels(), [128, 64, 0, 255]);
let vals: [f64; 4] = [128.0, 64.0, 0.0, 128.0];
let c = Color::from_slice(ColorMode::Rgb, &vals[..])?; // RGBA slice
assert_eq!(c.channels(), [128, 64, 0, 128]);sourcepub const fn from_hex_alpha(hex: u32) -> Self
pub const fn from_hex_alpha(hex: u32) -> Self
sourcepub const fn inverted(&self) -> Self
pub const fn inverted(&self) -> Self
Constructs a Color by inverting the RGBA values.
Example
let c = Color::from_hex(0xF0FF00);
assert_eq!(c.inverted().as_hex(), 0x0F00FF);sourcepub fn blended<A>(&self, bg: Color, alpha: A) -> Self where
A: Into<f64>,
pub fn blended<A>(&self, bg: Color, alpha: A) -> Self where
A: Into<f64>,
Constructs an opaque Color blended over a given background, using an alpha value.
sourcepub fn lerp<A>(&self, other: Color, amt: A) -> Self where
A: Into<f64>,
pub fn lerp<A>(&self, other: Color, amt: A) -> Self where
A: Into<f64>,
Constructs a Color by linear interpolating between two Colors by a given amount between
0.0 and 1.0.
Examples
let from = rgb!(255, 0, 0);
let to = rgb!(0, 100, 255);
let lerped = from.lerp(to, 0.5);
assert_eq!(lerped.channels(), [128, 50, 128, 255]);
let from = rgb!(255, 0, 0);
let to = hsb!(120.0, 80.0, 100.0, 0.5);
let lerped = from.lerp(to, 0.25); // `to` is implicity converted to RGB
assert_eq!(lerped.channels(), [204, 64, 13, 223]);sourceimpl Color
impl Color
sourcepub const fn new(r: u8, g: u8, b: u8) -> Self
pub const fn new(r: u8, g: u8, b: u8) -> Self
Constructs a Color with red, green, blue and max alpha.
Example
let c = Color::new(0, 0, 128);
assert_eq!(c.channels(), [0, 0, 128, 255]);sourcepub const fn new_alpha(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn new_alpha(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a Color with red, green, blue and alpha.
Example
let c = Color::new_alpha(0, 0, 128, 50);
assert_eq!(c.channels(), [0, 0, 128, 50]);sourcepub fn with_mode_alpha<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
pub fn with_mode_alpha<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
sourcepub const fn rgb(r: u8, g: u8, b: u8) -> Self
pub const fn rgb(r: u8, g: u8, b: u8) -> Self
Constructs a Color with red, green, blue and max alpha.
Alias for Color::new.
Example
let c = Color::rgb(128, 64, 0);
assert_eq!(c.channels(), [128, 64, 0, 255]);sourcepub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self
Constructs a Color with red, green, blue and alpha.
Alias for Color::new_alpha.
Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);sourcepub fn hsb<T: Into<f64>>(h: T, s: T, b: T) -> Self
pub fn hsb<T: Into<f64>>(h: T, s: T, b: T) -> Self
Constructs a Color with hue, saturation, brightness and max alpha.
Example
let c = Color::hsb(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 128, 36, 255]);sourcepub fn hsba<T: Into<f64>>(h: T, s: T, b: T, a: T) -> Self
pub fn hsba<T: Into<f64>>(h: T, s: T, b: T, a: T) -> Self
Constructs a Color with hue, saturation, brightness and alpha.
Example
let c = Color::hsba(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 128, 36, 128]);sourcepub fn hsl<T: Into<f64>>(h: T, s: T, l: T) -> Self
pub fn hsl<T: Into<f64>>(h: T, s: T, l: T) -> Self
Constructs a Color with hue, saturation, lightness and max alpha.
Example
let c = Color::hsl(126.0, 80.0, 50.0);
assert_eq!(c.channels(), [25, 230, 46, 255]);sourcepub fn hsla<T: Into<f64>>(h: T, s: T, l: T, a: T) -> Self
pub fn hsla<T: Into<f64>>(h: T, s: T, l: T, a: T) -> Self
Constructs a Color with hue, saturation, lightness and alpha.
Example
let c = Color::hsla(126.0, 80.0, 50.0, 0.5);
assert_eq!(c.channels(), [25, 230, 46, 128]);sourcepub fn from_levels<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
pub fn from_levels<T: Into<f64>>(
mode: Mode,
v1: T,
v2: T,
v3: T,
alpha: T
) -> Self
sourcepub fn random() -> Self
pub fn random() -> Self
Constructs a random Color with red, green, blue and max alpha.
Example
let c = Color::random();
// `c.channels()` will return something like:
// [207, 12, 217, 255]sourcepub fn random_alpha() -> Self
pub fn random_alpha() -> Self
Constructs a random Color with red, green, blue and alpha.
Example
let c = Color::random_alpha();
// `c.channels()` will return something like:
// [132, 159, 233, 76]sourcepub const fn as_hex_alpha(&self) -> u32
pub const fn as_hex_alpha(&self) -> u32
sourcepub const fn maxes(&self) -> [f64; 4]
pub const fn maxes(&self) -> [f64; 4]
Returns a list of max values for each color channel based on Mode.
Examples
let c = Color::rgb(0, 0, 0);
assert_eq!(c.maxes(), [255.0, 255.0, 255.0, 255.0]);
let c = Color::hsb(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);
let c = Color::hsl(0.0, 0.0, 0.0);
assert_eq!(c.maxes(), [360.0, 100.0, 100.0, 1.0]);sourcepub fn levels(&self) -> [f64; 4]
pub fn levels(&self) -> [f64; 4]
Returns the Color levels for the given Mode which range from 0.0..=1.0.
sourcepub fn set_levels(&mut self, levels: [f64; 4])
pub fn set_levels(&mut self, levels: [f64; 4])
sourcepub const fn channels(&self) -> [u8; 4]
pub const fn channels(&self) -> [u8; 4]
Returns the Color channels as [red, green, blue, alpha] which range from 0..=255.
Example
let c = Color::rgba(128, 64, 128, 128);
assert_eq!(c.channels(), [128, 64, 128, 128]);sourcepub const fn red(&self) -> u8
pub const fn red(&self) -> u8
Returns the red Color channel ranging from 0..=255.
Example
let c = Color::rgb(100, 0, 0);
assert_eq!(c.red(), 100);sourcepub fn set_red(&mut self, r: u8)
pub fn set_red(&mut self, r: u8)
Set the red Color channel ranging from 0..=255.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_red(100);
assert_eq!(c.channels(), [100, 0, 0, 255]);sourcepub const fn green(&self) -> u8
pub const fn green(&self) -> u8
Returns the green Color channel ranging from 0..=255.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.green(), 100);sourcepub fn set_green(&mut self, g: u8)
pub fn set_green(&mut self, g: u8)
Set the green Color channel ranging from 0..=255.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_green(100);
assert_eq!(c.channels(), [0, 100, 0, 255]);sourcepub const fn blue(&self) -> u8
pub const fn blue(&self) -> u8
Returns the blue Color channel ranging from 0..=255.
Example
let c = Color::rgb(0, 0, 100);
assert_eq!(c.blue(), 100);sourcepub fn set_blue(&mut self, b: u8)
pub fn set_blue(&mut self, b: u8)
Set the blue Color channel ranging from 0..=255.
Example
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_blue(100);
assert_eq!(c.channels(), [0, 0, 100, 255]);sourcepub const fn alpha(&self) -> u8
pub const fn alpha(&self) -> u8
Returns the alpha Color channel ranging from 0..=255.
Examples
let c = Color::rgba(0, 0, 0, 100);
assert_eq!(c.alpha(), 100);sourcepub fn set_alpha(&mut self, a: u8)
pub fn set_alpha(&mut self, a: u8)
Set the alpha Color channel ranging from 0..=255.
Examples
let mut c = Color::default();
assert_eq!(c.channels(), [0, 0, 0, 255]);
c.set_alpha(100);
assert_eq!(c.channels(), [0, 0, 0, 100]);sourcepub fn hue(&self) -> f64
pub fn hue(&self) -> f64
Returns the hue ranging from 0.0..=360.0.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.hue(), 120.0);sourcepub fn set_hue<H: Into<f64>>(&mut self, h: H)
pub fn set_hue<H: Into<f64>>(&mut self, h: H)
Set the hue ranging from 0.0..=360.0.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_hue(100.0);
assert_eq!(c.channels(), [43, 128, 0, 255]);sourcepub fn saturation(&self) -> f64
pub fn saturation(&self) -> f64
Returns the saturation ranging from 0.0..=100.0.
Example
let c = Color::rgb(0, 100, 0);
assert_eq!(c.saturation(), 100.0);sourcepub fn set_saturation<S: Into<f64>>(&mut self, s: S)
pub fn set_saturation<S: Into<f64>>(&mut self, s: S)
Set the saturation ranging from 0.0..=100.0. Defaults to Hsb if the
current mode is not Hsb or Hsl already.
Examples
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [128, 64, 64, 255]);
let mut c = Color::rgb(128, 0, 0);
c.set_mode(ColorMode::Hsl);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_saturation(50.0);
assert_eq!(c.channels(), [96, 32, 32, 255]);sourcepub fn brightness(&self) -> f64
pub fn brightness(&self) -> f64
Returns the brightness ranging from 0.0..=100.0.
Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.brightness(), 40.0);sourcepub fn set_brightness<B: Into<f64>>(&mut self, b: B)
pub fn set_brightness<B: Into<f64>>(&mut self, b: B)
Set the brightness ranging from 0.0..=100.0.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_brightness(90.0);
assert_eq!(c.channels(), [230, 0, 0, 255]);sourcepub fn lightness(&self) -> f64
pub fn lightness(&self) -> f64
Returns the lightness ranging from 0.0..=100.0.
Example
let c = Color::rgb(0, 102, 0);
assert_eq!(c.lightness(), 20.0);sourcepub fn set_lightness<L: Into<f64>>(&mut self, l: L)
pub fn set_lightness<L: Into<f64>>(&mut self, l: L)
Set the lightness ranging from 0.0..=100.0.
Example
let mut c = Color::rgb(128, 0, 0);
assert_eq!(c.channels(), [128, 0, 0, 255]);
c.set_lightness(90.0);
assert_eq!(c.channels(), [255, 204, 204, 255]);Methods from Deref<Target = [u8; 4]>
1.57.0 · sourcepub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub fn as_slice(&self) -> &[T]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Returns a slice containing the entire array. Equivalent to &s[..].
sourcepub fn each_ref(&self) -> [&T; N]
🔬 This is a nightly-only experimental API. (array_methods)
pub fn each_ref(&self) -> [&T; N]
array_methods)Borrows each element and returns an array of references with the same
size as self.
Example
#![feature(array_methods)]
let floats = [3.1, 2.7, -1.0];
let float_refs: [&f64; 3] = floats.each_ref();
assert_eq!(float_refs, [&3.1, &2.7, &-1.0]);This method is particularly useful if combined with other methods, like
map. This way, you can avoid moving the original
array if its elements are not Copy.
#![feature(array_methods)]
let strings = ["Ferris".to_string(), "♥".to_string(), "Rust".to_string()];
let is_ascii = strings.each_ref().map(|s| s.is_ascii());
assert_eq!(is_ascii, [true, false, true]);
// We can still access the original array: it has not been moved.
assert_eq!(strings.len(), 3);sourcepub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
🔬 This is a nightly-only experimental API. (split_array)
pub fn split_array_ref<const M: usize>(&self) -> (&[T; M], &[T])
split_array)Divides one array reference into two at an index.
The first will contain all indices from [0, M) (excluding
the index M itself) and the second will contain all
indices from [M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.split_array_ref::<0>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<2>();
assert_eq!(left, &[1, 2]);
assert_eq!(right, &[3, 4, 5, 6]);
}
{
let (left, right) = v.split_array_ref::<6>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}sourcepub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
🔬 This is a nightly-only experimental API. (split_array)
pub fn rsplit_array_ref<const M: usize>(&self) -> (&[T], &[T; M])
split_array)Divides one array reference into two at an index from the end.
The first will contain all indices from [0, N - M) (excluding
the index N - M itself) and the second will contain all
indices from [N - M, N) (excluding the index N itself).
Panics
Panics if M > N.
Examples
#![feature(split_array)]
let v = [1, 2, 3, 4, 5, 6];
{
let (left, right) = v.rsplit_array_ref::<0>();
assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
assert_eq!(right, &[]);
}
{
let (left, right) = v.rsplit_array_ref::<2>();
assert_eq!(left, &[1, 2, 3, 4]);
assert_eq!(right, &[5, 6]);
}
{
let (left, right) = v.rsplit_array_ref::<6>();
assert_eq!(left, &[]);
assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
}Trait Implementations
sourceimpl AddAssign<Color> for Color
impl AddAssign<Color> for Color
sourcefn add_assign(&mut self, other: Color)
fn add_assign(&mut self, other: Color)
Performs the += operation. Read more
sourceimpl AddAssign<u8> for Color
impl AddAssign<u8> for Color
sourcefn add_assign(&mut self, val: u8)
fn add_assign(&mut self, val: u8)
Performs the += operation. Read more
sourceimpl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl DivAssign<f32> for Color where
f32: Into<f64>,
impl DivAssign<f32> for Color where
f32: Into<f64>,
sourcefn div_assign(&mut self, s: f32)
fn div_assign(&mut self, s: f32)
Performs the /= operation. Read more
sourceimpl DivAssign<f64> for Color where
f64: Into<f64>,
impl DivAssign<f64> for Color where
f64: Into<f64>,
sourcefn div_assign(&mut self, s: f64)
fn div_assign(&mut self, s: f64)
Performs the /= operation. Read more
sourceimpl DivAssign<i128> for Color
impl DivAssign<i128> for Color
sourcefn div_assign(&mut self, s: i128)
fn div_assign(&mut self, s: i128)
Performs the /= operation. Read more
sourceimpl DivAssign<i16> for Color where
i16: Into<f64>,
impl DivAssign<i16> for Color where
i16: Into<f64>,
sourcefn div_assign(&mut self, s: i16)
fn div_assign(&mut self, s: i16)
Performs the /= operation. Read more
sourceimpl DivAssign<i32> for Color where
i32: Into<f64>,
impl DivAssign<i32> for Color where
i32: Into<f64>,
sourcefn div_assign(&mut self, s: i32)
fn div_assign(&mut self, s: i32)
Performs the /= operation. Read more
sourceimpl DivAssign<i64> for Color
impl DivAssign<i64> for Color
sourcefn div_assign(&mut self, s: i64)
fn div_assign(&mut self, s: i64)
Performs the /= operation. Read more
sourceimpl DivAssign<i8> for Color where
i8: Into<f64>,
impl DivAssign<i8> for Color where
i8: Into<f64>,
sourcefn div_assign(&mut self, s: i8)
fn div_assign(&mut self, s: i8)
Performs the /= operation. Read more
sourceimpl DivAssign<isize> for Color
impl DivAssign<isize> for Color
sourcefn div_assign(&mut self, s: isize)
fn div_assign(&mut self, s: isize)
Performs the /= operation. Read more
sourceimpl DivAssign<u128> for Color
impl DivAssign<u128> for Color
sourcefn div_assign(&mut self, s: u128)
fn div_assign(&mut self, s: u128)
Performs the /= operation. Read more
sourceimpl DivAssign<u16> for Color where
u16: Into<f64>,
impl DivAssign<u16> for Color where
u16: Into<f64>,
sourcefn div_assign(&mut self, s: u16)
fn div_assign(&mut self, s: u16)
Performs the /= operation. Read more
sourceimpl DivAssign<u32> for Color where
u32: Into<f64>,
impl DivAssign<u32> for Color where
u32: Into<f64>,
sourcefn div_assign(&mut self, s: u32)
fn div_assign(&mut self, s: u32)
Performs the /= operation. Read more
sourceimpl DivAssign<u64> for Color
impl DivAssign<u64> for Color
sourcefn div_assign(&mut self, s: u64)
fn div_assign(&mut self, s: u64)
Performs the /= operation. Read more
sourceimpl DivAssign<u8> for Color where
u8: Into<f64>,
impl DivAssign<u8> for Color where
u8: Into<f64>,
sourcefn div_assign(&mut self, s: u8)
fn div_assign(&mut self, s: u8)
Performs the /= operation. Read more
sourceimpl DivAssign<usize> for Color
impl DivAssign<usize> for Color
sourcefn div_assign(&mut self, s: usize)
fn div_assign(&mut self, s: usize)
Performs the /= operation. Read more
sourceimpl FromStr for Color
impl FromStr for Color
sourcefn from_str(string: &str) -> Result<Self, Self::Err>
fn from_str(string: &str) -> Result<Self, Self::Err>
Converts to Color from a hexadecimal string.
Examples
use std::str::FromStr;
let c = Color::from_str("#F0F")?; // 3-digit Hex string
assert_eq!(c.channels(), [255, 0, 255, 255]);
let c = Color::from_str("#F0F5")?; // 4-digit Hex string
assert_eq![c.channels(), [255, 0, 255, 85]];
let c = Color::from_str("#F0F5BF")?; // 6-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 255]);
let c = Color::from_str("#F0F5BF5F")?; // 8-digit Hex string
assert_eq!(c.channels(), [240, 245, 191, 95]);sourceimpl MulAssign<f32> for Color where
f32: Into<f64>,
impl MulAssign<f32> for Color where
f32: Into<f64>,
sourcefn mul_assign(&mut self, s: f32)
fn mul_assign(&mut self, s: f32)
Performs the *= operation. Read more
sourceimpl MulAssign<f64> for Color where
f64: Into<f64>,
impl MulAssign<f64> for Color where
f64: Into<f64>,
sourcefn mul_assign(&mut self, s: f64)
fn mul_assign(&mut self, s: f64)
Performs the *= operation. Read more
sourceimpl MulAssign<i128> for Color
impl MulAssign<i128> for Color
sourcefn mul_assign(&mut self, s: i128)
fn mul_assign(&mut self, s: i128)
Performs the *= operation. Read more
sourceimpl MulAssign<i16> for Color where
i16: Into<f64>,
impl MulAssign<i16> for Color where
i16: Into<f64>,
sourcefn mul_assign(&mut self, s: i16)
fn mul_assign(&mut self, s: i16)
Performs the *= operation. Read more
sourceimpl MulAssign<i32> for Color where
i32: Into<f64>,
impl MulAssign<i32> for Color where
i32: Into<f64>,
sourcefn mul_assign(&mut self, s: i32)
fn mul_assign(&mut self, s: i32)
Performs the *= operation. Read more
sourceimpl MulAssign<i64> for Color
impl MulAssign<i64> for Color
sourcefn mul_assign(&mut self, s: i64)
fn mul_assign(&mut self, s: i64)
Performs the *= operation. Read more
sourceimpl MulAssign<i8> for Color where
i8: Into<f64>,
impl MulAssign<i8> for Color where
i8: Into<f64>,
sourcefn mul_assign(&mut self, s: i8)
fn mul_assign(&mut self, s: i8)
Performs the *= operation. Read more
sourceimpl MulAssign<isize> for Color
impl MulAssign<isize> for Color
sourcefn mul_assign(&mut self, s: isize)
fn mul_assign(&mut self, s: isize)
Performs the *= operation. Read more
sourceimpl MulAssign<u128> for Color
impl MulAssign<u128> for Color
sourcefn mul_assign(&mut self, s: u128)
fn mul_assign(&mut self, s: u128)
Performs the *= operation. Read more
sourceimpl MulAssign<u16> for Color where
u16: Into<f64>,
impl MulAssign<u16> for Color where
u16: Into<f64>,
sourcefn mul_assign(&mut self, s: u16)
fn mul_assign(&mut self, s: u16)
Performs the *= operation. Read more
sourceimpl MulAssign<u32> for Color where
u32: Into<f64>,
impl MulAssign<u32> for Color where
u32: Into<f64>,
sourcefn mul_assign(&mut self, s: u32)
fn mul_assign(&mut self, s: u32)
Performs the *= operation. Read more
sourceimpl MulAssign<u64> for Color
impl MulAssign<u64> for Color
sourcefn mul_assign(&mut self, s: u64)
fn mul_assign(&mut self, s: u64)
Performs the *= operation. Read more
sourceimpl MulAssign<u8> for Color where
u8: Into<f64>,
impl MulAssign<u8> for Color where
u8: Into<f64>,
sourcefn mul_assign(&mut self, s: u8)
fn mul_assign(&mut self, s: u8)
Performs the *= operation. Read more
sourceimpl MulAssign<usize> for Color
impl MulAssign<usize> for Color
sourcefn mul_assign(&mut self, s: usize)
fn mul_assign(&mut self, s: usize)
Performs the *= operation. Read more
sourceimpl SubAssign<Color> for Color
impl SubAssign<Color> for Color
sourcefn sub_assign(&mut self, other: Color)
fn sub_assign(&mut self, other: Color)
Performs the -= operation. Read more
sourceimpl SubAssign<u8> for Color
impl SubAssign<u8> for Color
sourcefn sub_assign(&mut self, val: u8)
fn sub_assign(&mut self, val: u8)
Performs the -= operation. Read more
impl Copy for Color
impl Eq 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