use coolor::{Color, Hsl};
pub trait ColorAlgorithm: Sized + Copy{
fn gen_color(&self, follower_proportion: f32) -> Color;
}
#[derive(Copy, Clone)]
pub struct LightnessDescending {
pub hue: f32,
pub saturation: f32
}
impl ColorAlgorithm for LightnessDescending {
fn gen_color(&self, follower_proportion: f32) -> Color {
assert!(follower_proportion >= 0.0 && follower_proportion <= 1.0,
"follower_proportion outside of expected bounds (0, 1)");
assert!(self.hue >= 0.0 && self.hue < 360.0, "hue outside of expected bounds (0, 360]");
assert!(self.saturation >= 0.0 && self.saturation <= 1.0,
"saturation outside of expected bounds (0, 1)");
coolor::Color::Hsl(
Hsl{
h:self.hue,
s:self.saturation,
l:((0.9 - follower_proportion).max(0.1))
}
)
}
}
#[derive(Clone, Copy)]
pub struct SaturationDescending{
pub hue: f32,
pub lightness: f32
}
impl ColorAlgorithm for SaturationDescending {
fn gen_color(&self, follower_proportion: f32) -> Color {
assert!(follower_proportion >= 0.0 && follower_proportion <= 1.0,
"follower_proportion outside of expected bounds (0, 1)");
assert!(self.hue >= 0.0 && self.hue < 360.0, "hue outside of expected bounds (0, 360]");
assert!(self.lightness >= 0.0 && self.lightness <= 1.0,
"lightness outside of expected bounds (0, 1)");
coolor::Color::Hsl(
Hsl{
h:self.hue,
l:self.lightness,
s:((1.0 - follower_proportion).max(0.0))
}
)
}
}
#[derive(Clone, Copy)]
pub struct HueVariation {
pub saturation: f32,
pub lightness: f32
}
impl ColorAlgorithm for HueVariation {
fn gen_color(&self, follower_proportion: f32) -> Color {
assert!(follower_proportion >= 0.0 && follower_proportion <= 1.0,
"follower_proportion outside of expected bounds (0, 1)");
assert!(self.saturation >= 0.0 && self.saturation <= 1.0,
"saturation outside of expected bounds (0, 1)");
assert!(self.lightness >= 0.0 && self.lightness <= 1.0,
"lightness outside of expected bounds (0, 1)");
coolor::Color::Hsl(
Hsl{
h:follower_proportion * 360.0,
s:self.saturation,
l:self.lightness
}
)
}
}