pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
32-bit RGBA color.
Fields§
§r: u8Red component.
g: u8Green component.
b: u8Blue component.
a: u8Alpha component.
Implementations§
Source§impl Color
impl Color
Sourcepub fn rgb(r: f64, g: f64, b: f64) -> Self
pub fn rgb(r: f64, g: f64, b: f64) -> Self
Create a color from three floating point values, each in the range 0.0 to 1.0.
The interpretation is the same as rgb8, and no greater precision is (currently) assumed.
Sourcepub fn rgba(r: f64, g: f64, b: f64, a: f64) -> Self
pub fn rgba(r: f64, g: f64, b: f64, a: f64) -> Self
Create a color from four floating point values, each in the range 0.0 to 1.0.
The interpretation is the same as rgba32, and no greater precision is (currently) assumed.
Sourcepub fn hlc(h: f64, l: f64, c: f64) -> Self
pub fn hlc(h: f64, l: f64, c: f64) -> Self
Create a color from a CIEL*a*b* polar (also known as CIE HCL) specification.
The h parameter is an angle in degrees, with 0 roughly magenta, 90
roughly yellow, 180 roughly cyan, and 270 roughly blue. The l
parameter is perceptual luminance, with 0 black and 100 white.
The c parameter is a chrominance concentration, with 0 grayscale
and a nominal maximum of 127 (in the future, higher values might
be useful, for high gamut contexts).
Currently this is just converted into sRGB, but in the future as we support high-gamut colorspaces, it can be used to specify more colors or existing colors with a higher accuracy.
Currently out-of-gamut values are clipped to the nearest sRGB color, which is perhaps not ideal (the clipping might change the hue). See https://github.com/d3/d3-color/issues/33 for discussion.
Sourcepub fn hlca(h: f64, l: f64, c: f64, a: f64) -> Color
pub fn hlca(h: f64, l: f64, c: f64, a: f64) -> Color
Create a color from a CIEL*a*b* polar specification and alpha.
The a value represents alpha in the range 0.0 to 1.0.
Sourcepub fn parse(s: &str) -> Option<Self>
pub fn parse(s: &str) -> Option<Self>
Parses a color from a string.
Currently accepts CSS style hexidecimal colors of the forms #RGB, #RGBA, #RRGGBB, #RRGGBBAA or the name of an SVG color such as “aliceblue”.
Sourcepub fn with_alpha_factor(self, alpha: f32) -> Self
pub fn with_alpha_factor(self, alpha: f32) -> Self
Returns the color with the alpha component multiplied by the specified factor.
Sourcepub fn to_premul_u32(self) -> u32
pub fn to_premul_u32(self) -> u32
Returns the color as a packed premultiplied value.
Source§impl Color
Named SVG colors.
impl Color
Named SVG colors.
Sourcepub const ALICE_BLUE: Color
pub const ALICE_BLUE: Color
Alice blue (240, 248, 255, 255)
Sourcepub const ANTIQUE_WHITE: Color
pub const ANTIQUE_WHITE: Color
Antique white (250, 235, 215, 255)
Sourcepub const AQUAMARINE: Color
pub const AQUAMARINE: Color
Aquamarine (127, 255, 212, 255)
Sourcepub const BLANCHED_ALMOND: Color
pub const BLANCHED_ALMOND: Color
Blanched almond (255, 235, 205, 255)
Sourcepub const BLUE_VIOLET: Color
pub const BLUE_VIOLET: Color
Blue violet (138, 43, 226, 255)
Sourcepub const CADET_BLUE: Color
pub const CADET_BLUE: Color
Cadet blue (95, 158, 160, 255)
Sourcepub const CHARTREUSE: Color
pub const CHARTREUSE: Color
Chartreuse (127, 255, 0, 255)
Sourcepub const CORNFLOWER_BLUE: Color
pub const CORNFLOWER_BLUE: Color
Cornflower blue (100, 149, 237, 255)
Sourcepub const DARK_GOLDENROD: Color
pub const DARK_GOLDENROD: Color
Dark goldenrod (184, 134, 11, 255)
Sourcepub const DARK_GREEN: Color
pub const DARK_GREEN: Color
Dark green (0, 100, 0, 255)
Sourcepub const DARK_KHAKI: Color
pub const DARK_KHAKI: Color
Dark khaki (189, 183, 107, 255)
Sourcepub const DARK_MAGENTA: Color
pub const DARK_MAGENTA: Color
Dark magenta (139, 0, 139, 255)
Sourcepub const DARK_OLIVE_GREEN: Color
pub const DARK_OLIVE_GREEN: Color
Dark olive green (85, 107, 47, 255)
Sourcepub const DARK_ORANGE: Color
pub const DARK_ORANGE: Color
Dark orange (255, 140, 0, 255)
Sourcepub const DARK_ORCHID: Color
pub const DARK_ORCHID: Color
Dark orchid (153, 50, 204, 255)
Sourcepub const DARK_SALMON: Color
pub const DARK_SALMON: Color
Dark salmon (233, 150, 122, 255)
Sourcepub const DARK_SEA_GREEN: Color
pub const DARK_SEA_GREEN: Color
Dark sea green (143, 188, 143, 255)
Sourcepub const DARK_SLATE_BLUE: Color
pub const DARK_SLATE_BLUE: Color
Dark slate blue (72, 61, 139, 255)
Sourcepub const DARK_SLATE_GRAY: Color
pub const DARK_SLATE_GRAY: Color
Dark slate gray (47, 79, 79, 255)
Sourcepub const DARK_TURQUOISE: Color
pub const DARK_TURQUOISE: Color
Dark turquoise (0, 206, 209, 255)
Sourcepub const DARK_VIOLET: Color
pub const DARK_VIOLET: Color
Dark violet (148, 0, 211, 255)
Sourcepub const DEEP_SKY_BLUE: Color
pub const DEEP_SKY_BLUE: Color
Deep sky blue (0, 191, 255, 255)
Sourcepub const DODGER_BLUE: Color
pub const DODGER_BLUE: Color
Dodger blue (30, 144, 255, 255)
Sourcepub const FLORAL_WHITE: Color
pub const FLORAL_WHITE: Color
Floral white (255, 250, 240, 255)
Sourcepub const FOREST_GREEN: Color
pub const FOREST_GREEN: Color
Forest green (34, 139, 34, 255)
Sourcepub const GHOST_WHITE: Color
pub const GHOST_WHITE: Color
Ghost white (248, 248, 255, 255)
Sourcepub const GREEN_YELLOW: Color
pub const GREEN_YELLOW: Color
Green yellow (173, 255, 47, 255)
Sourcepub const INDIAN_RED: Color
pub const INDIAN_RED: Color
Indian red (205, 92, 92, 255)
Sourcepub const LAVENDER_BLUSH: Color
pub const LAVENDER_BLUSH: Color
Lavender blush (255, 240, 245, 255)
Sourcepub const LAWN_GREEN: Color
pub const LAWN_GREEN: Color
Lawn green (124, 252, 0, 255)
Sourcepub const LEMON_CHIFFON: Color
pub const LEMON_CHIFFON: Color
Lemon chiffon (255, 250, 205, 255)
Sourcepub const LIGHT_BLUE: Color
pub const LIGHT_BLUE: Color
Light blue (173, 216, 230, 255)
Sourcepub const LIGHT_CORAL: Color
pub const LIGHT_CORAL: Color
Light coral (240, 128, 128, 255)
Sourcepub const LIGHT_CYAN: Color
pub const LIGHT_CYAN: Color
Light cyan (224, 255, 255, 255)
Sourcepub const LIGHT_GOLDENROD_YELLOW: Color
pub const LIGHT_GOLDENROD_YELLOW: Color
Light goldenrod yellow (250, 250, 210, 255)
Sourcepub const LIGHT_GRAY: Color
pub const LIGHT_GRAY: Color
Light gray (211, 211, 211, 255)
Sourcepub const LIGHT_GREEN: Color
pub const LIGHT_GREEN: Color
Light green (144, 238, 144, 255)
Sourcepub const LIGHT_PINK: Color
pub const LIGHT_PINK: Color
Light pink (255, 182, 193, 255)
Sourcepub const LIGHT_SALMON: Color
pub const LIGHT_SALMON: Color
Light salmon (255, 160, 122, 255)
Sourcepub const LIGHT_SEA_GREEN: Color
pub const LIGHT_SEA_GREEN: Color
Light sea green (32, 178, 170, 255)
Sourcepub const LIGHT_SKY_BLUE: Color
pub const LIGHT_SKY_BLUE: Color
Light sky blue (135, 206, 250, 255)
Sourcepub const LIGHT_SLATE_GRAY: Color
pub const LIGHT_SLATE_GRAY: Color
Light slate gray (119, 136, 153, 255)
Sourcepub const LIGHT_STEEL_BLUE: Color
pub const LIGHT_STEEL_BLUE: Color
Light steel blue (176, 196, 222, 255)
Sourcepub const LIGHT_YELLOW: Color
pub const LIGHT_YELLOW: Color
Light yellow (255, 255, 224, 255)
Sourcepub const LIME_GREEN: Color
pub const LIME_GREEN: Color
Lime green (50, 205, 50, 255)
Sourcepub const MEDIUM_AQUAMARINE: Color
pub const MEDIUM_AQUAMARINE: Color
Medium aquamarine (102, 205, 170, 255)
Sourcepub const MEDIUM_BLUE: Color
pub const MEDIUM_BLUE: Color
Medium blue (0, 0, 205, 255)
Sourcepub const MEDIUM_ORCHID: Color
pub const MEDIUM_ORCHID: Color
Medium orchid (186, 85, 211, 255)
Sourcepub const MEDIUM_PURPLE: Color
pub const MEDIUM_PURPLE: Color
Medium purple (147, 112, 219, 255)
Sourcepub const MEDIUM_SEA_GREEN: Color
pub const MEDIUM_SEA_GREEN: Color
Medium sea green (60, 179, 113, 255)
Sourcepub const MEDIUM_SLATE_BLUE: Color
pub const MEDIUM_SLATE_BLUE: Color
Medium slate blue (123, 104, 238, 255)
Sourcepub const MEDIUM_SPRING_GREEN: Color
pub const MEDIUM_SPRING_GREEN: Color
Medium spring green (0, 250, 154, 255)
Sourcepub const MEDIUM_TURQUOISE: Color
pub const MEDIUM_TURQUOISE: Color
Medium turquoise (72, 209, 204, 255)
Sourcepub const MEDIUM_VIOLET_RED: Color
pub const MEDIUM_VIOLET_RED: Color
Medium violet red (199, 21, 133, 255)
Sourcepub const MIDNIGHT_BLUE: Color
pub const MIDNIGHT_BLUE: Color
Midnight blue (25, 25, 112, 255)
Sourcepub const MINT_CREAM: Color
pub const MINT_CREAM: Color
Mint cream (245, 255, 250, 255)
Sourcepub const MISTY_ROSE: Color
pub const MISTY_ROSE: Color
Misty rose (255, 228, 225, 255)
Sourcepub const NAVAJO_WHITE: Color
pub const NAVAJO_WHITE: Color
Navajo white (255, 222, 173, 255)
Sourcepub const OLIVE_DRAB: Color
pub const OLIVE_DRAB: Color
Olive drab (107, 142, 35, 255)
Sourcepub const ORANGE_RED: Color
pub const ORANGE_RED: Color
Orange red (255, 69, 0, 255)
Sourcepub const PALE_GOLDENROD: Color
pub const PALE_GOLDENROD: Color
Pale goldenrod (238, 232, 170, 255)
Sourcepub const PALE_GREEN: Color
pub const PALE_GREEN: Color
Pale green (152, 251, 152, 255)
Sourcepub const PALE_TURQUOISE: Color
pub const PALE_TURQUOISE: Color
Pale turquoise (175, 238, 238, 255)
Sourcepub const PALE_VIOLET_RED: Color
pub const PALE_VIOLET_RED: Color
Pale violet red (219, 112, 147, 255)
Sourcepub const PAPAYA_WHIP: Color
pub const PAPAYA_WHIP: Color
Papaya whip (255, 239, 213, 255)
Sourcepub const PEACH_PUFF: Color
pub const PEACH_PUFF: Color
Peach puff (255, 218, 185, 255)
Sourcepub const POWDER_BLUE: Color
pub const POWDER_BLUE: Color
Powder blue (176, 224, 230, 255)
Sourcepub const REBECCA_PURPLE: Color
pub const REBECCA_PURPLE: Color
Rebecca purple (102, 51, 153, 255)
Sourcepub const ROSY_BROWN: Color
pub const ROSY_BROWN: Color
Rosy brown (188, 143, 143, 255)
Sourcepub const ROYAL_BLUE: Color
pub const ROYAL_BLUE: Color
Royal blue (65, 105, 225, 255)
Sourcepub const SADDLE_BROWN: Color
pub const SADDLE_BROWN: Color
Saddle brown (139, 69, 19, 255)
Sourcepub const SANDY_BROWN: Color
pub const SANDY_BROWN: Color
Sandy brown (244, 164, 96, 255)
Sourcepub const SLATE_BLUE: Color
pub const SLATE_BLUE: Color
Slate blue (106, 90, 205, 255)
Sourcepub const SLATE_GRAY: Color
pub const SLATE_GRAY: Color
Slate gray (112, 128, 144, 255)
Sourcepub const SPRING_GREEN: Color
pub const SPRING_GREEN: Color
Spring green (0, 255, 127, 255)
Sourcepub const STEEL_BLUE: Color
pub const STEEL_BLUE: Color
Steel blue (70, 130, 180, 255)
Sourcepub const TRANSPARENT: Color
pub const TRANSPARENT: Color
Transparent (0, 0, 0, 0)
Sourcepub const WHITE_SMOKE: Color
pub const WHITE_SMOKE: Color
White smoke (245, 245, 245, 255)
Sourcepub const YELLOW_GREEN: Color
pub const YELLOW_GREEN: Color
Yellow green (154, 205, 50, 255)