1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
extern crate image;
use image::Rgba;
extern crate rand;
use rand::{thread_rng, Rng};
const PREDEFINED_COLORS: [Rgba<u8>; 14] = [
Rgba([252, 41, 34, 255]),
Rgba([6, 124, 77, 255]),
Rgba([83, 101, 255, 255]),
Rgba([247, 244, 139, 255]),
Rgba([147, 112, 246, 255]),
Rgba([158, 194, 255, 255]),
Rgba([255, 255, 255, 255]),
Rgba([125, 125, 125, 255]),
Rgba([244, 164, 96, 255]),
Rgba([252, 145, 212, 255]),
Rgba([181, 101, 29, 255]),
Rgba([180, 215, 162, 255]),
Rgba([142, 32, 21, 255]),
Rgba([33, 42, 165, 255]),
];
#[derive(Clone, Copy)]
pub struct Palette {
body_color: Rgba<u8>,
border_color: Rgba<u8>,
}
impl Palette {
pub fn new(color: Rgba<u8>, border_ratio: u8) -> Palette {
let Rgba{ 0: rgb } = color;
Palette {
body_color: color,
border_color: Rgba([rgb[0] / border_ratio, rgb[1] / border_ratio,
rgb[2] / border_ratio, 255]),
}
}
pub fn get_body_color(&self) -> Rgba<u8> {
self.body_color
}
pub fn get_border_color(&self) -> Rgba<u8> {
self.border_color
}
}
#[derive(Clone, Copy)]
pub enum PaletteGeneration {
RandomPredefinedColors,
}
impl PaletteGeneration {
pub fn run(&self, border_ratio: u8) -> Palette {
match self {
PaletteGeneration::RandomPredefinedColors => {
let mut rng = thread_rng();
Palette::new(PREDEFINED_COLORS[rng.gen_range(0, 13)], border_ratio)
},
}
}
}