mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
switch sequencer to ItemColorTriplet
This commit is contained in:
parent
cb8dfb4bd7
commit
87379ff76b
5 changed files with 25 additions and 15 deletions
|
|
@ -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,)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue