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
69
70
71
72
73
74
75
76
77
#[derive(Copy, Clone, Debug)]
pub struct Color {
pub red: f32,
pub green: f32,
pub blue: f32,
pub alpha: f32,
}
impl Color {
pub const fn new(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
Self {
red,
green,
blue,
alpha,
}
}
pub fn from_bytes(red: u8, green: u8, blue: u8, alpha: u8) -> Self {
Self {
red: red as f32 / u8::MAX as f32,
green: green as f32 / u8::MAX as f32,
blue: blue as f32 / u8::MAX as f32,
alpha: alpha as f32 / u8::MAX as f32,
}
}
}
impl Default for Color {
fn default() -> Self {
Color {
red: 1.,
green: 1.,
blue: 1.,
alpha: 1.,
}
}
}
impl From<Color> for [f32; 4] {
fn from(c: Color) -> Self {
[c.red, c.green, c.blue, c.alpha]
}
}
impl From<[f32; 4]> for Color {
fn from([red, green, blue, alpha]: [f32; 4]) -> Self {
Self {
red,
green,
blue,
alpha,
}
}
}
impl From<Color> for solstice::Color<solstice::ClampedF32> {
fn from(c: Color) -> Self {
Self {
red: c.red.into(),
blue: c.blue.into(),
green: c.green.into(),
alpha: c.alpha.into(),
}
}
}
impl From<Color> for mint::Vector4<f32> {
fn from(c: Color) -> Self {
Self {
x: c.red,
y: c.green,
z: c.blue,
w: c.alpha,
}
}
}