ableos_userland/libraries/able_graphics_library/src/engine3d/color.rs

22 lines
636 B
Rust

pub struct Color3 {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Color3 {
/// Usage
/// The alpha value is a number between 0.0 and 1.0, which represents the transparency
/// or translucency of the other color.
pub fn blend(&self, other: &Self, alpha: f32) -> Self {
let r = (1.0 - alpha) * f32::from(self.r) + alpha * f32::from(other.r);
let g = (1.0 - alpha) * f32::from(self.g) + alpha * f32::from(other.g);
let b = (1.0 - alpha) * f32::from(self.b) + alpha * f32::from(other.b);
Self {
r: r as u8,
g: g as u8,
b: b as u8,
}
}
}