diff options
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/common.rs b/src/common.rs index 918c59c..120d8b4 100644 --- a/src/common.rs +++ b/src/common.rs @@ -25,11 +25,51 @@ pub struct Color { pub b: f32, } +pub enum ColorName { + Black, + White, + Red, + Lime, + Blue, + Yellow, + Cyan, + Magenta, + Silver, + Gray, + Maroon, + Olive, + Green, + Purple, + Teal, + Navy, +} + impl Color { pub fn new(r: f32, g: f32, b: f32) -> Self { Self { r, g, b } } + pub fn from_name(name: ColorName) -> Self { + match name { + ColorName::Black => { Self::new(0.0, 0.0, 0.0) } + ColorName::White => { Self::new(1.0, 1.0, 1.0) } + ColorName::Red => { Self::new(1.0, 0.0, 0.0) } + ColorName::Lime => { Self::new(0.0, 1.0, 0.0) } + ColorName::Blue => { Self::new(0.0, 0.0, 1.0) } + ColorName::Yellow => { Self::new(1.0, 1.0, 0.0) } + ColorName::Cyan => { Self::new(0.0, 1.0, 1.0) } + ColorName::Magenta => { Self::new(1.0, 0.0, 1.0) } + ColorName::Silver => { Self::new(0.75, 0.75, 0.75) } + ColorName::Gray => { Self::new(0.5, 0.5, 0.5) } + ColorName::Maroon => { Self::new(0.5, 0.0, 0.0) } + ColorName::Olive => { Self::new(0.5, 0.5, 0.0)} + ColorName::Green => { Self::new(0.0, 0.5, 0.0) } + ColorName::Purple => { Self::new(0.5, 0.0, 0.5) } + ColorName::Teal => { Self::new(0.0, 0.5, 0.5) } + ColorName::Navy => { Self::new(0.0, 0.0, 0.5) } + } + } + pub fn mul_scalar(&self, scalar: f32) -> Color { Self { r: self.r * scalar, |