primitives/foundation/colorschemes/
split_complementary.rs1#![allow(unused_imports)]
2use crate::foundation::colorspace::{Color, HsvColor};
3
4use super::ryb_rotate;
5
6#[derive(Debug, Clone)]
12pub struct SplitComplementary {
13 colors: Vec<Color>,
14 primary_color: Color,
15}
16
17impl SplitComplementary {
18 pub fn new(primary: Color) -> Self {
20 let mut instance = Self {
21 colors: Vec::new(),
22 primary_color: primary,
23 };
24 instance.generate();
25
26 instance
27 }
28
29 fn generate(&mut self) {
30 self.colors = vec![self.primary_color];
31
32 let mut c1: HsvColor = ryb_rotate(self.primary_color, 150.0);
34 c1.value += 10.0;
35 self.colors.push(c1.into());
36
37 let mut c2: HsvColor = ryb_rotate(self.primary_color, 210.0);
38 c2.value += 10.0;
39 self.colors.push(c2.into());
40 }
41
42 pub fn num_of_colors(&self) -> usize {
44 self.colors.len()
45 }
46
47 pub fn get_color(&self, index: usize) -> Option<Color> {
49 self.colors.get(index).copied()
50 }
51
52 pub fn primary_color(&self) -> Color {
54 self.primary_color
55 }
56
57 pub fn set_primary_color(&mut self, val: Color) {
59 self.primary_color = val;
60 self.generate();
61 }
62}