randomize arrangement bg color

This commit is contained in:
🪞👃🪞 2024-10-18 20:05:38 +03:00
parent cd2a94d808
commit cc578b0b52
3 changed files with 20 additions and 5 deletions

View file

@ -36,11 +36,19 @@ tui_style!(WHITE_NOT_DIM_BOLD =
pub fn random_okhsl () -> Okhsl<f32> {
let mut rng = thread_rng();
UniformOkhsl::new(
Okhsl::new(-180.0, 0.01, 0.1),
Okhsl::new(-180.0, 0.01, 0.2),
Okhsl::new( 180.0, 0.9, 0.5),
).sample(&mut rng)
}
pub fn random_okhsl_dark () -> Okhsl<f32> {
let mut rng = thread_rng();
UniformOkhsl::new(
Okhsl::new(-180.0, 0.01, 0.05),
Okhsl::new( 180.0, 0.5, 0.2),
).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,)
@ -50,6 +58,10 @@ pub fn random_color () -> Color {
okhsl_to_rgb(random_okhsl())
}
pub fn random_color_dark () -> Color {
okhsl_to_rgb(random_okhsl_dark())
}
pub fn random_color_near (color: Color, distance: f32) -> Color {
let (r, g, b) = if let Color::Rgb(r, g, b) = color {
(r, g, b)