Add a color (2 colors can be now defined for a machine).
[temp2RGB.git] / src / rgb.rs
1 use serde::{Deserialize, Serialize};
2
3 #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
4 pub struct RGB {
5 pub red: u8,
6 pub green: u8,
7 pub blue: u8,
8 }
9
10 // 'value' is between 0 and 1.
11 pub fn linear_interpolation(color1: RGB, color2: RGB, value: f32) -> RGB {
12 let red = (color1.red as f32 + (color2.red as f32 - color1.red as f32) * value) as u8;
13 let green = (color1.green as f32 + (color2.green as f32 - color1.green as f32) * value) as u8;
14 let blue = (color1.blue as f32 + (color2.blue as f32 - color1.blue as f32) * value) as u8;
15
16 RGB { red, green, blue }
17 }