diff --git a/crates/bevy_color/src/color_range.rs b/crates/bevy_color/src/color_range.rs index 0f1c8472a1dc35..16d6f048666701 100644 --- a/crates/bevy_color/src/color_range.rs +++ b/crates/bevy_color/src/color_range.rs @@ -22,17 +22,18 @@ impl ColorRange for Range { #[cfg(test)] mod tests { use super::*; + use crate::palettes::basic; use crate::{LinearRgba, Srgba}; #[test] fn test_color_range() { - let range = Srgba::RED..Srgba::BLUE; - assert_eq!(range.at(0.0), Srgba::RED); + let range = basic::RED..basic::BLUE; + assert_eq!(range.at(0.0), basic::RED); assert_eq!(range.at(0.5), Srgba::new(0.5, 0.0, 0.5, 1.0)); - assert_eq!(range.at(1.0), Srgba::BLUE); + assert_eq!(range.at(1.0), basic::BLUE); - let lred: LinearRgba = Srgba::RED.into(); - let lblue: LinearRgba = Srgba::BLUE.into(); + let lred: LinearRgba = basic::RED.into(); + let lblue: LinearRgba = basic::BLUE.into(); let range = lred..lblue; assert_eq!(range.at(0.0), lred); diff --git a/crates/bevy_color/src/lib.rs b/crates/bevy_color/src/lib.rs index fb028c0006f57e..f731c0b8d79248 100644 --- a/crates/bevy_color/src/lib.rs +++ b/crates/bevy_color/src/lib.rs @@ -72,6 +72,7 @@ mod hsla; mod lcha; mod linear_rgba; mod oklaba; +pub mod palettes; mod srgba; #[cfg(test)] mod test_colors; diff --git a/crates/bevy_color/src/palettes/basic.rs b/crates/bevy_color/src/palettes/basic.rs new file mode 100644 index 00000000000000..e1f1c532592ea9 --- /dev/null +++ b/crates/bevy_color/src/palettes/basic.rs @@ -0,0 +1,39 @@ +//! Named colors from the CSS1 specification, also known as +//! [basic colors](https://en.wikipedia.org/wiki/Web_colors#Basic_colors). +//! This is the same set of colors used in the +//! [VGA graphcs standard](https://en.wikipedia.org/wiki/Video_Graphics_Array). + +use crate::Srgba; + +///
+pub const BLACK: Srgba = Srgba::new(0.0, 0.0, 0.0, 1.0); +///
+pub const BLUE: Srgba = Srgba::new(0.0, 0.0, 1.0, 1.0); +///
+pub const CYAN: Srgba = Srgba::new(0.0, 1.0, 1.0, 1.0); +///
+pub const GREEN: Srgba = Srgba::new(0.0, 0.5, 0.0, 1.0); +///
+pub const FUCHSIA: Srgba = Srgba::new(1.0, 0.0, 1.0, 1.0); +///
+pub const GRAY: Srgba = Srgba::new(0.5, 0.5, 0.5, 1.0); +///
+pub const LIME: Srgba = Srgba::new(0.0, 1.0, 0.0, 1.0); +///
+pub const MAROON: Srgba = Srgba::new(0.5, 0.0, 0.0, 1.0); +///
+pub const NAVY: Srgba = Srgba::new(0.0, 0.0, 0.5, 1.0); +///
+pub const OLIVE: Srgba = Srgba::new(0.5, 0.5, 0.0, 1.0); +///
+pub const PURPLE: Srgba = Srgba::new(0.5, 0.0, 0.5, 1.0); +///
+pub const RED: Srgba = Srgba::new(1.0, 0.0, 0.0, 1.0); +///
+pub const SILVER: Srgba = Srgba::new(0.75, 0.75, 0.75, 1.0); +///
+pub const TEAL: Srgba = Srgba::new(0.0, 0.5, 0.5, 1.0); +///
+pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0); +///
+pub const YELLOW: Srgba = Srgba::new(1.0, 1.0, 0.0, 1.0); diff --git a/crates/bevy_color/src/palettes/css.rs b/crates/bevy_color/src/palettes/css.rs new file mode 100644 index 00000000000000..7cd08d5216b552 --- /dev/null +++ b/crates/bevy_color/src/palettes/css.rs @@ -0,0 +1,301 @@ +//! [Extended colors from the CSS4 specification](https://en.wikipedia.org/wiki/Web_colors#Extended_colors), +//! Also known as X11 colors, which were standardized in HTML 4.0. + +use crate::Srgba; + +///
+pub const ALICE_BLUE: Srgba = Srgba::new(0.941, 0.973, 1.0, 1.0); +///
+pub const ANTIQUE_WHITE: Srgba = Srgba::new(0.98, 0.922, 0.843, 1.0); +///
+pub const AQUA: Srgba = Srgba::new(0.0, 1.0, 1.0, 1.0); +///
+pub const AQUAMARINE: Srgba = Srgba::new(0.498, 1.0, 0.831, 1.0); +///
+pub const AZURE: Srgba = Srgba::new(0.941, 1.0, 1.0, 1.0); +///
+pub const BEIGE: Srgba = Srgba::new(0.961, 0.961, 0.863, 1.0); +///
+pub const BISQUE: Srgba = Srgba::new(1.0, 0.894, 0.769, 1.0); +///
+pub const BLACK: Srgba = Srgba::new(0.0, 0.0, 0.0, 1.0); +///
+pub const BLANCHED_ALMOND: Srgba = Srgba::new(1.0, 0.922, 0.804, 1.0); +///
+pub const BLUE: Srgba = Srgba::new(0.0, 0.0, 1.0, 1.0); +///
+pub const BLUE_VIOLET: Srgba = Srgba::new(0.541, 0.169, 0.886, 1.0); +///
+pub const BROWN: Srgba = Srgba::new(0.647, 0.165, 0.165, 1.0); +///
+pub const BURLYWOOD: Srgba = Srgba::new(0.871, 0.722, 0.529, 1.0); +///
+pub const CADET_BLUE: Srgba = Srgba::new(0.373, 0.62, 0.627, 1.0); +///
+pub const CHARTREUSE: Srgba = Srgba::new(0.498, 1.0, 0.0, 1.0); +///
+pub const CHOCOLATE: Srgba = Srgba::new(0.824, 0.412, 0.118, 1.0); +///
+pub const CORAL: Srgba = Srgba::new(1.0, 0.498, 0.314, 1.0); +///
+pub const CORNFLOWER_BLUE: Srgba = Srgba::new(0.392, 0.584, 0.929, 1.0); +///
+pub const CORNSILK: Srgba = Srgba::new(1.0, 0.973, 0.863, 1.0); +///
+pub const CRIMSON: Srgba = Srgba::new(0.863, 0.078, 0.235, 1.0); +///
+pub const CYAN: Srgba = Srgba::new(0.0, 1.0, 1.0, 1.0); +///
+pub const DARK_BLUE: Srgba = Srgba::new(0.0, 0.0, 0.545, 1.0); +///
+pub const DARK_CYAN: Srgba = Srgba::new(0.0, 0.545, 0.545, 1.0); +///
+pub const DARK_GOLDENROD: Srgba = Srgba::new(0.722, 0.525, 0.043, 1.0); +///
+pub const DARK_GRAY: Srgba = Srgba::new(0.663, 0.663, 0.663, 1.0); +///
+pub const DARK_GREEN: Srgba = Srgba::new(0.0, 0.392, 0.0, 1.0); +///
+pub const DARK_GREY: Srgba = Srgba::new(0.663, 0.663, 0.663, 1.0); +///
+pub const DARK_KHAKI: Srgba = Srgba::new(0.741, 0.718, 0.42, 1.0); +///
+pub const DARK_MAGENTA: Srgba = Srgba::new(0.545, 0.0, 0.545, 1.0); +///
+pub const DARK_OLIVEGREEN: Srgba = Srgba::new(0.333, 0.42, 0.184, 1.0); +///
+pub const DARK_ORANGE: Srgba = Srgba::new(1.0, 0.549, 0.0, 1.0); +///
+pub const DARK_ORCHID: Srgba = Srgba::new(0.6, 0.196, 0.8, 1.0); +///
+pub const DARK_RED: Srgba = Srgba::new(0.545, 0.0, 0.0, 1.0); +///
+pub const DARK_SALMON: Srgba = Srgba::new(0.914, 0.588, 0.478, 1.0); +///
+pub const DARK_SEA_GREEN: Srgba = Srgba::new(0.561, 0.737, 0.561, 1.0); +///
+pub const DARK_SLATE_BLUE: Srgba = Srgba::new(0.282, 0.239, 0.545, 1.0); +///
+pub const DARK_SLATE_GRAY: Srgba = Srgba::new(0.184, 0.31, 0.31, 1.0); +///
+pub const DARK_SLATE_GREY: Srgba = Srgba::new(0.184, 0.31, 0.31, 1.0); +///
+pub const DARK_TURQUOISE: Srgba = Srgba::new(0.0, 0.808, 0.82, 1.0); +///
+pub const DARK_VIOLET: Srgba = Srgba::new(0.58, 0.0, 0.827, 1.0); +///
+pub const DEEP_PINK: Srgba = Srgba::new(1.0, 0.078, 0.576, 1.0); +///
+pub const DEEP_SKY_BLUE: Srgba = Srgba::new(0.0, 0.749, 1.0, 1.0); +///
+pub const DIM_GRAY: Srgba = Srgba::new(0.412, 0.412, 0.412, 1.0); +///
+pub const DIM_GREY: Srgba = Srgba::new(0.412, 0.412, 0.412, 1.0); +///
+pub const DODGER_BLUE: Srgba = Srgba::new(0.118, 0.565, 1.0, 1.0); +///
+pub const FIRE_BRICK: Srgba = Srgba::new(0.698, 0.133, 0.133, 1.0); +///
+pub const FLORAL_WHITE: Srgba = Srgba::new(1.0, 0.98, 0.941, 1.0); +///
+pub const FOREST_GREEN: Srgba = Srgba::new(0.133, 0.545, 0.133, 1.0); +///
+pub const FUCHSIA: Srgba = Srgba::new(1.0, 0.0, 1.0, 1.0); +///
+pub const GAINSBORO: Srgba = Srgba::new(0.863, 0.863, 0.863, 1.0); +///
+pub const GHOST_WHITE: Srgba = Srgba::new(0.973, 0.973, 1.0, 1.0); +///
+pub const GOLD: Srgba = Srgba::new(1.0, 0.843, 0.0, 1.0); +///
+pub const GOLDENROD: Srgba = Srgba::new(0.855, 0.647, 0.125, 1.0); +///
+pub const GRAY: Srgba = Srgba::new(0.502, 0.502, 0.502, 1.0); +///
+pub const GREEN: Srgba = Srgba::new(0.0, 0.502, 0.0, 1.0); +///
+pub const GREEN_YELLOW: Srgba = Srgba::new(0.678, 1.0, 0.184, 1.0); +///
+pub const GREY: Srgba = Srgba::new(0.502, 0.502, 0.502, 1.0); +///
+pub const HONEYDEW: Srgba = Srgba::new(0.941, 1.0, 0.941, 1.0); +///
+pub const HOT_PINK: Srgba = Srgba::new(1.0, 0.412, 0.706, 1.0); +///
+pub const INDIAN_RED: Srgba = Srgba::new(0.804, 0.361, 0.361, 1.0); +///
+pub const INDIGO: Srgba = Srgba::new(0.294, 0.0, 0.51, 1.0); +///
+pub const IVORY: Srgba = Srgba::new(1.0, 1.0, 0.941, 1.0); +///
+pub const KHAKI: Srgba = Srgba::new(0.941, 0.902, 0.549, 1.0); +///
+pub const LAVENDER: Srgba = Srgba::new(0.902, 0.902, 0.98, 1.0); +///
+pub const LAVENDER_BLUSH: Srgba = Srgba::new(1.0, 0.941, 0.961, 1.0); +///
+pub const LAWN_GREEN: Srgba = Srgba::new(0.486, 0.988, 0.0, 1.0); +///
+pub const LEMON_CHIFFON: Srgba = Srgba::new(1.0, 0.98, 0.804, 1.0); +///
+pub const LIGHT_BLUE: Srgba = Srgba::new(0.678, 0.847, 0.902, 1.0); +///
+pub const LIGHT_CORAL: Srgba = Srgba::new(0.941, 0.502, 0.502, 1.0); +///
+pub const LIGHT_CYAN: Srgba = Srgba::new(0.878, 1.0, 1.0, 1.0); +///
+pub const LIGHT_GOLDENROD_YELLOW: Srgba = Srgba::new(0.98, 0.98, 0.824, 1.0); +///
+pub const LIGHT_GRAY: Srgba = Srgba::new(0.827, 0.827, 0.827, 1.0); +///
+pub const LIGHT_GREEN: Srgba = Srgba::new(0.565, 0.933, 0.565, 1.0); +///
+pub const LIGHT_GREY: Srgba = Srgba::new(0.827, 0.827, 0.827, 1.0); +///
+pub const LIGHT_PINK: Srgba = Srgba::new(1.0, 0.714, 0.757, 1.0); +///
+pub const LIGHT_SALMON: Srgba = Srgba::new(1.0, 0.627, 0.478, 1.0); +///
+pub const LIGHT_SEA_GREEN: Srgba = Srgba::new(0.125, 0.698, 0.667, 1.0); +///
+pub const LIGHT_SKY_BLUE: Srgba = Srgba::new(0.529, 0.808, 0.98, 1.0); +///
+pub const LIGHT_SLATE_GRAY: Srgba = Srgba::new(0.467, 0.533, 0.6, 1.0); +///
+pub const LIGHT_SLATE_GREY: Srgba = Srgba::new(0.467, 0.533, 0.6, 1.0); +///
+pub const LIGHT_STEEL_BLUE: Srgba = Srgba::new(0.69, 0.769, 0.871, 1.0); +///
+pub const LIGHT_YELLOW: Srgba = Srgba::new(1.0, 1.0, 0.878, 1.0); +///
+pub const LIME: Srgba = Srgba::new(0.0, 1.0, 0.0, 1.0); +///
+pub const LIMEGREEN: Srgba = Srgba::new(0.196, 0.804, 0.196, 1.0); +///
+pub const LINEN: Srgba = Srgba::new(0.98, 0.941, 0.902, 1.0); +///
+pub const MAGENTA: Srgba = Srgba::new(1.0, 0.0, 1.0, 1.0); +///
+pub const MAROON: Srgba = Srgba::new(0.502, 0.0, 0.0, 1.0); +///
+pub const MEDIUM_AQUAMARINE: Srgba = Srgba::new(0.4, 0.804, 0.667, 1.0); +///
+pub const MEDIUM_BLUE: Srgba = Srgba::new(0.0, 0.0, 0.804, 1.0); +///
+pub const MEDIUM_ORCHID: Srgba = Srgba::new(0.729, 0.333, 0.827, 1.0); +///
+pub const MEDIUM_PURPLE: Srgba = Srgba::new(0.576, 0.439, 0.859, 1.0); +///
+pub const MEDIUM_SEA_GREEN: Srgba = Srgba::new(0.235, 0.702, 0.443, 1.0); +///
+pub const MEDIUM_SLATE_BLUE: Srgba = Srgba::new(0.482, 0.408, 0.933, 1.0); +///
+pub const MEDIUM_SPRING_GREEN: Srgba = Srgba::new(0.0, 0.98, 0.604, 1.0); +///
+pub const MEDIUM_TURQUOISE: Srgba = Srgba::new(0.282, 0.82, 0.8, 1.0); +///
+pub const MEDIUM_VIOLET_RED: Srgba = Srgba::new(0.78, 0.082, 0.522, 1.0); +///
+pub const MIDNIGHT_BLUE: Srgba = Srgba::new(0.098, 0.098, 0.439, 1.0); +///
+pub const MINT_CREAM: Srgba = Srgba::new(0.961, 1.0, 0.98, 1.0); +///
+pub const MISTY_ROSE: Srgba = Srgba::new(1.0, 0.894, 0.882, 1.0); +///
+pub const MOCCASIN: Srgba = Srgba::new(1.0, 0.894, 0.71, 1.0); +///
+pub const NAVAJO_WHITE: Srgba = Srgba::new(1.0, 0.871, 0.678, 1.0); +///
+pub const NAVY: Srgba = Srgba::new(0.0, 0.0, 0.502, 1.0); +///
+pub const OLD_LACE: Srgba = Srgba::new(0.992, 0.961, 0.902, 1.0); +///
+pub const OLIVE: Srgba = Srgba::new(0.502, 0.502, 0.0, 1.0); +///
+pub const OLIVE_DRAB: Srgba = Srgba::new(0.42, 0.557, 0.137, 1.0); +///
+pub const ORANGE: Srgba = Srgba::new(1.0, 0.647, 0.0, 1.0); +///
+pub const ORANGE_RED: Srgba = Srgba::new(1.0, 0.271, 0.0, 1.0); +///
+pub const ORCHID: Srgba = Srgba::new(0.855, 0.439, 0.839, 1.0); +///
+pub const PALE_GOLDENROD: Srgba = Srgba::new(0.933, 0.91, 0.667, 1.0); +///
+pub const PALE_GREEN: Srgba = Srgba::new(0.596, 0.984, 0.596, 1.0); +///
+pub const PALE_TURQUOISE: Srgba = Srgba::new(0.686, 0.933, 0.933, 1.0); +///
+pub const PALE_VIOLETRED: Srgba = Srgba::new(0.859, 0.439, 0.576, 1.0); +///
+pub const PAPAYA_WHIP: Srgba = Srgba::new(1.0, 0.937, 0.835, 1.0); +///
+pub const PEACHPUFF: Srgba = Srgba::new(1.0, 0.855, 0.725, 1.0); +///
+pub const PERU: Srgba = Srgba::new(0.804, 0.522, 0.247, 1.0); +///
+pub const PINK: Srgba = Srgba::new(1.0, 0.753, 0.796, 1.0); +///
+pub const PLUM: Srgba = Srgba::new(0.867, 0.627, 0.867, 1.0); +///
+pub const POWDER_BLUE: Srgba = Srgba::new(0.69, 0.878, 0.902, 1.0); +///
+pub const PURPLE: Srgba = Srgba::new(0.502, 0.0, 0.502, 1.0); +///
+pub const REBECCA_PURPLE: Srgba = Srgba::new(0.4, 0.2, 0.6, 1.0); +///
+pub const RED: Srgba = Srgba::new(1.0, 0.0, 0.0, 1.0); +///
+pub const ROSY_BROWN: Srgba = Srgba::new(0.737, 0.561, 0.561, 1.0); +///
+pub const ROYAL_BLUE: Srgba = Srgba::new(0.255, 0.412, 0.882, 1.0); +///
+pub const SADDLE_BROWN: Srgba = Srgba::new(0.545, 0.271, 0.075, 1.0); +///
+pub const SALMON: Srgba = Srgba::new(0.98, 0.502, 0.447, 1.0); +///
+pub const SANDY_BROWN: Srgba = Srgba::new(0.957, 0.643, 0.376, 1.0); +///
+pub const SEA_GREEN: Srgba = Srgba::new(0.18, 0.545, 0.341, 1.0); +///
+pub const SEASHELL: Srgba = Srgba::new(1.0, 0.961, 0.933, 1.0); +///
+pub const SIENNA: Srgba = Srgba::new(0.627, 0.322, 0.176, 1.0); +///
+pub const SILVER: Srgba = Srgba::new(0.753, 0.753, 0.753, 1.0); +///
+pub const SKY_BLUE: Srgba = Srgba::new(0.529, 0.808, 0.922, 1.0); +///
+pub const SLATE_BLUE: Srgba = Srgba::new(0.416, 0.353, 0.804, 1.0); +///
+pub const SLATE_GRAY: Srgba = Srgba::new(0.439, 0.502, 0.565, 1.0); +///
+pub const SLATE_GREY: Srgba = Srgba::new(0.439, 0.502, 0.565, 1.0); +///
+pub const SNOW: Srgba = Srgba::new(1.0, 0.98, 0.98, 1.0); +///
+pub const SPRING_GREEN: Srgba = Srgba::new(0.0, 1.0, 0.498, 1.0); +///
+pub const STEEL_BLUE: Srgba = Srgba::new(0.275, 0.51, 0.706, 1.0); +///
+pub const TAN: Srgba = Srgba::new(0.824, 0.706, 0.549, 1.0); +///
+pub const TEAL: Srgba = Srgba::new(0.0, 0.502, 0.502, 1.0); +///
+pub const THISTLE: Srgba = Srgba::new(0.847, 0.749, 0.847, 1.0); +///
+pub const TOMATO: Srgba = Srgba::new(1.0, 0.388, 0.278, 1.0); +///
+pub const TURQUOISE: Srgba = Srgba::new(0.251, 0.878, 0.816, 1.0); +///
+pub const VIOLET: Srgba = Srgba::new(0.933, 0.51, 0.933, 1.0); +///
+pub const WHEAT: Srgba = Srgba::new(0.961, 0.871, 0.702, 1.0); +///
+pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0); +///
+pub const WHITE_SMOKE: Srgba = Srgba::new(0.961, 0.961, 0.961, 1.0); +///
+pub const YELLOW: Srgba = Srgba::new(1.0, 1.0, 0.0, 1.0); +///
+pub const YELLOW_GREEN: Srgba = Srgba::new(0.604, 0.804, 0.196, 1.0); diff --git a/crates/bevy_color/src/palettes/mod.rs b/crates/bevy_color/src/palettes/mod.rs new file mode 100644 index 00000000000000..f062ebedbabc16 --- /dev/null +++ b/crates/bevy_color/src/palettes/mod.rs @@ -0,0 +1,4 @@ +//! Color palettes consisting of collections of const colors. + +pub mod basic; +pub mod css; diff --git a/crates/bevy_color/src/srgba.rs b/crates/bevy_color/src/srgba.rs index a25bb58baa8290..3795399f4e299d 100644 --- a/crates/bevy_color/src/srgba.rs +++ b/crates/bevy_color/src/srgba.rs @@ -26,41 +26,11 @@ impl Srgba { ///
pub const BLACK: Srgba = Srgba::new(0.0, 0.0, 0.0, 1.0); - ///
- pub const BLUE: Srgba = Srgba::new(0.0, 0.0, 1.0, 1.0); - ///
- pub const CYAN: Srgba = Srgba::new(0.0, 1.0, 1.0, 1.0); - ///
- pub const DARK_GRAY: Srgba = Srgba::new(0.25, 0.25, 0.25, 1.0); - ///
- pub const GREEN: Srgba = Srgba::new(0.0, 0.5, 0.0, 1.0); - ///
- pub const FUCHSIA: Srgba = Srgba::new(1.0, 0.0, 1.0, 1.0); - ///
- pub const GRAY: Srgba = Srgba::new(0.5, 0.5, 0.5, 1.0); - ///
- pub const LIME: Srgba = Srgba::new(0.0, 1.0, 0.0, 1.0); - ///
- pub const MAROON: Srgba = Srgba::new(0.5, 0.0, 0.0, 1.0); - ///
- pub const NAVY: Srgba = Srgba::new(0.0, 0.0, 0.5, 1.0); ///
#[doc(alias = "transparent")] pub const NONE: Srgba = Srgba::new(0.0, 0.0, 0.0, 0.0); - ///
- pub const OLIVE: Srgba = Srgba::new(0.5, 0.5, 0.0, 1.0); - ///
- pub const PURPLE: Srgba = Srgba::new(0.5, 0.0, 0.5, 1.0); - ///
- pub const RED: Srgba = Srgba::new(1.0, 0.0, 0.0, 1.0); - ///
- pub const SILVER: Srgba = Srgba::new(0.75, 0.75, 0.75, 1.0); - ///
- pub const TEAL: Srgba = Srgba::new(0.0, 0.5, 0.5, 1.0); ///
pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0); - ///
- pub const YELLOW: Srgba = Srgba::new(1.0, 1.0, 0.0, 1.0); /// Construct a new [`Srgba`] color from components. ///