diff --git a/src/color.rs b/src/color.rs index c410468..d113697 100644 --- a/src/color.rs +++ b/src/color.rs @@ -75,6 +75,21 @@ impl Into<[f32; 3]> for Color { } } +impl Into<[f32; 4]> for Color { + fn into(self) -> [f32; 4] { + match self { + Color::White => [1.0, 1.0, 1.0, 1.0], + Color::Black => [0.0, 0.0, 0.0, 1.0], + Color::Red => [1.0, 0.0, 0.0, 1.0], + Color::Blue => [0.0, 0.0, 1.0, 1.0], + Color::Green => [0.0, 1.0, 0.0, 1.0], + Color::Orange => [1.0, 0.65, 0.0, 1.0], + Color::Yellow => [1.0, 1.0, 0.0, 1.0], + Color::Custom(r, g, b) => [r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0], + } + } +} + impl Into<[u8; 3]> for Color { fn into(self) -> [u8; 3] { match self { @@ -90,6 +105,21 @@ impl Into<[u8; 3]> for Color { } } +impl Into<[u8; 4]> for Color { + fn into(self) -> [u8; 4] { + match self { + Color::White => [255, 255, 255, 255], + Color::Black => [0, 0, 0, 255], + Color::Red => [255, 0, 0, 255], + Color::Blue => [0, 0, 255, 255], + Color::Green => [0, 255, 0, 255], + Color::Orange => [255, 166, 0, 255], + Color::Yellow => [255, 255, 0, 255], + Color::Custom(r, g, b) => [r, g, b, 255], + } + } +} + impl Mul for Color { type Output = Self;