Skip to main content

color_mix/
lib.rs

1//! # Art
2//!
3//! A library for modeling artistic concepts.
4
5pub mod kinds {
6    /// The primary colors according to the RYB color model.
7    #[derive(Debug, PartialEq)]
8    pub enum PrimaryColor {
9        Red,
10        Yellow,
11        Blue,
12    }
13
14    #[derive(Debug, PartialEq)]
15    /// The secondary colors according to the RYB color model.
16    pub enum SecondaryColor {
17        Orange,
18        Green,
19        Purple,
20    }
21}
22
23pub mod utils {
24    use crate::kinds::*;
25
26    /// Combines two primary colors in equal amounts to create
27    /// a secondary color.
28    pub fn mix(c1: PrimaryColor, c2: PrimaryColor) -> SecondaryColor {
29        // --snip--
30        if c1 == PrimaryColor::Red && c2 == PrimaryColor::Yellow {
31            SecondaryColor::Orange
32        } else if c1 == PrimaryColor::Red && c2 == PrimaryColor::Blue {
33            SecondaryColor::Purple
34        } else if c1 == PrimaryColor::Yellow && c2 == PrimaryColor::Blue {
35            SecondaryColor::Green
36        } else {
37            panic!("Wrong colors: {:?} and {:?}! You should be ashamed of yourself.", c1, c2);
38        }
39    }
40}