#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RGBA {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}
impl RGBA {
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
}
pub fn to_rgb(self) -> (RGB, u8) {
(
RGB {
r: self.r,
g: self.g,
b: self.b,
},
self.a,
)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RGB {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl RGB {
pub fn add_rgba(self, other: RGBA) -> Self {
let (other, alpha) = other.to_rgb();
self.lerp(&other, alpha as f64 / 255.0)
}
pub fn lerp(&self, other: &Self, a: f64) -> Self {
RGB {
r: ((1.0 - a) * self.r as f64 + a * other.r as f64) as u8,
g: ((1.0 - a) * self.g as f64 + a * other.g as f64) as u8,
b: ((1.0 - a) * self.b as f64 + a * other.b as f64) as u8,
}
}
}
pub const TRANSPARANT: RGBA = RGBA {
r: 0,
g: 0,
b: 0,
a: 0,
};
pub const BLACK: RGBA = RGBA {
r: 0,
g: 0,
b: 0,
a: 255,
};
pub const WHITE: RGBA = RGBA {
r: 255,
g: 255,
b: 255,
a: 255,
};
pub const RED: RGBA = RGBA {
r: 255,
g: 0,
b: 0,
a: 255,
};
pub const GREEN: RGBA = RGBA {
r: 0,
g: 255,
b: 0,
a: 255,
};
pub const BLUE: RGBA = RGBA {
r: 0,
g: 0,
b: 255,
a: 255,
};