switch sequencer to ItemColorTriplet

This commit is contained in:
🪞👃🪞 2024-11-02 15:16:02 +02:00
parent cb8dfb4bd7
commit 87379ff76b
5 changed files with 25 additions and 15 deletions

View file

@ -36,8 +36,8 @@ impl ItemColor {
let hi = Okhsl::new( 180.0, 0.5, 0.2);
UniformOkhsl::new(lo, hi).sample(&mut rng).into()
}
pub fn random_near (base: Self, distance: f32) -> Self {
base.mix(Self::random(), distance)
pub fn random_near (color: Self, distance: f32) -> Self {
color.mix(Self::random(), distance)
}
pub fn mix (&self, other: Self, distance: f32) -> Self {
if distance > 1.0 { panic!("color mixing takes distance between 0.0 and 1.0"); }
@ -55,6 +55,14 @@ impl From<ItemColor> for ItemColorTriplet {
Self { base, light: light.into(), dark: dark.into() }
}
}
impl ItemColorTriplet {
pub fn random () -> Self {
ItemColor::random().into()
}
pub fn random_near (color: Self, distance: f32) -> Self {
color.base.mix(ItemColor::random(), distance).into()
}
}
pub fn okhsl_to_rgb (color: Okhsl<f32>) -> Color {
let Srgb { red, green, blue, .. }: Srgb<f32> = Srgb::from_color_unclamped(color);
Color::Rgb((red * 255.0) as u8, (green * 255.0) as u8, (blue * 255.0) as u8,)