mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 04:06:45 +01:00
remove last freestanding random color fn
This commit is contained in:
parent
eb1e3179a4
commit
cb8dfb4bd7
2 changed files with 18 additions and 19 deletions
|
|
@ -24,16 +24,24 @@ impl From<Color> for ItemColor {
|
|||
fn from (rgb: Color) -> Self { Self { rgb, okhsl: rgb_to_okhsl(rgb) } }
|
||||
}
|
||||
impl ItemColor {
|
||||
pub fn random () -> Self { random_okhsl().into() }
|
||||
pub fn random () -> Self {
|
||||
let mut rng = thread_rng();
|
||||
let lo = Okhsl::new(-180.0, 0.01, 0.2);
|
||||
let hi = Okhsl::new( 180.0, 0.9, 0.5);
|
||||
UniformOkhsl::new(lo, hi).sample(&mut rng).into()
|
||||
}
|
||||
pub fn random_dark () -> Self {
|
||||
let mut rng = thread_rng();
|
||||
let lo = Okhsl::new(-180.0, 0.01, 0.05);
|
||||
let hi = Okhsl::new( 180.0, 0.5, 0.2);
|
||||
UniformOkhsl::new(lo, hi).sample(&mut rng).into()
|
||||
}
|
||||
pub fn random_near (other: Self, distance: f32) -> Self {
|
||||
if distance > 1.0 { panic!("ItemColor::random_near takes distance between 0.0 and 1.0"); }
|
||||
other.okhsl.mix(random_okhsl(), distance).into()
|
||||
pub fn random_near (base: Self, distance: f32) -> Self {
|
||||
base.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"); }
|
||||
self.okhsl.mix(other.okhsl, distance).into()
|
||||
}
|
||||
}
|
||||
impl From<ItemColor> for ItemColorTriplet {
|
||||
|
|
@ -47,19 +55,10 @@ impl From<ItemColor> for ItemColorTriplet {
|
|||
Self { base, light: light.into(), dark: dark.into() }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn random_okhsl () -> Okhsl<f32> {
|
||||
let mut rng = thread_rng();
|
||||
let lo = Okhsl::new(-180.0, 0.01, 0.2);
|
||||
let hi = Okhsl::new( 180.0, 0.9, 0.5);
|
||||
UniformOkhsl::new(lo, hi).sample(&mut rng)
|
||||
}
|
||||
|
||||
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,)
|
||||
}
|
||||
|
||||
pub fn rgb_to_okhsl (color: Color) -> Okhsl<f32> {
|
||||
if let Color::Rgb(r, g, b) = color {
|
||||
Okhsl::from_color(Srgb::new(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue