Skip to content

Commit

Permalink
bevy_color: adding 'palettes' module. (bevyengine#12067)
Browse files Browse the repository at this point in the history
Two palettes are added:
- Basic: A basic palette with 16 colors.
- CSS: A palette with the colors from the "extended CSS"/X11/HTML4.0
color names.
  • Loading branch information
viridia authored and msvbg committed Feb 26, 2024
1 parent 952e629 commit 092daaa
Show file tree
Hide file tree
Showing 6 changed files with 351 additions and 35 deletions.
11 changes: 6 additions & 5 deletions crates/bevy_color/src/color_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ impl<T: Mix> ColorRange<T> for Range<T> {
#[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);
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ mod hsla;
mod lcha;
mod linear_rgba;
mod oklaba;
pub mod palettes;
mod srgba;
#[cfg(test)]
mod test_colors;
Expand Down
39 changes: 39 additions & 0 deletions crates/bevy_color/src/palettes/basic.rs
Original file line number Diff line number Diff line change
@@ -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;

/// <div style="background-color:rgb(0%, 0%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const BLACK: Srgba = Srgba::new(0.0, 0.0, 0.0, 1.0);
/// <div style="background-color:rgb(0%, 0%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const BLUE: Srgba = Srgba::new(0.0, 0.0, 1.0, 1.0);
/// <div style="background-color:rgb(0%, 100%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const CYAN: Srgba = Srgba::new(0.0, 1.0, 1.0, 1.0);
/// <div style="background-color:rgb(0%, 50%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const GREEN: Srgba = Srgba::new(0.0, 0.5, 0.0, 1.0);
/// <div style="background-color:rgb(100%, 0%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const FUCHSIA: Srgba = Srgba::new(1.0, 0.0, 1.0, 1.0);
/// <div style="background-color:rgb(50%, 50%, 50%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const GRAY: Srgba = Srgba::new(0.5, 0.5, 0.5, 1.0);
/// <div style="background-color:rgb(0%, 100%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const LIME: Srgba = Srgba::new(0.0, 1.0, 0.0, 1.0);
/// <div style="background-color:rgb(50%, 0%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const MAROON: Srgba = Srgba::new(0.5, 0.0, 0.0, 1.0);
/// <div style="background-color:rgb(0%, 0%, 50%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const NAVY: Srgba = Srgba::new(0.0, 0.0, 0.5, 1.0);
/// <div style="background-color:rgb(50%, 50%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const OLIVE: Srgba = Srgba::new(0.5, 0.5, 0.0, 1.0);
/// <div style="background-color:rgb(50%, 0%, 50%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const PURPLE: Srgba = Srgba::new(0.5, 0.0, 0.5, 1.0);
/// <div style="background-color:rgb(100%, 0%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const RED: Srgba = Srgba::new(1.0, 0.0, 0.0, 1.0);
/// <div style="background-color:rgb(75%, 75%, 75%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const SILVER: Srgba = Srgba::new(0.75, 0.75, 0.75, 1.0);
/// <div style="background-color:rgb(0%, 50%, 50%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const TEAL: Srgba = Srgba::new(0.0, 0.5, 0.5, 1.0);
/// <div style="background-color:rgb(100%, 100%, 100%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const WHITE: Srgba = Srgba::new(1.0, 1.0, 1.0, 1.0);
/// <div style="background-color:rgb(100%, 100%, 0%); width: 10px; padding: 10px; border: 1px solid;"></div>
pub const YELLOW: Srgba = Srgba::new(1.0, 1.0, 0.0, 1.0);
Loading

0 comments on commit 092daaa

Please sign in to comment.