My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/rst-client/src/color.rs

32 lines
760 B

use ggez::graphics::Color as EzColor;
use rst_core::data::Color;
pub fn to(Color(r, g, b): Color) -> EzColor {
EzColor::from_rgb(r, g, b)
}
/// A utility for manipulating colours
pub trait ColorUtils {
fn darken(&self, factor: u8) -> Self;
fn brighten(&self, factor: u8) -> Self;
}
impl ColorUtils for EzColor {
fn darken(&self, factor: u8) -> Self {
Self {
r: self.r / factor as f32,
g: self.g / factor as f32,
b: self.b / factor as f32,
a: self.a,
}
}
fn brighten(&self, factor: u8) -> Self {
Self {
r: self.r * factor as f32,
g: self.g * factor as f32,
b: self.b * factor as f32,
a: self.a,
}
}
}