scene and track gradients

This commit is contained in:
🪞👃🪞 2024-10-11 18:30:45 +03:00
parent 6bee5b0bcd
commit 12df6d5af2
4 changed files with 41 additions and 48 deletions

View file

@ -35,21 +35,24 @@ tui_style!(STYLE_LABEL =
tui_style!(STYLE_VALUE =
Some(Color::White), None, None, Modifier::BOLD, Modifier::DIM);
pub fn random_color () -> Color {
pub fn random_okhsl () -> Okhsl<f32> {
let mut rng = thread_rng();
let color: Okhsl<f32> = Okhsl::new(
Okhsl::new(
rng.gen::<f32>() * 360f32 - 180f32,
rng.gen::<f32>(),
rng.gen::<f32>() * 0.5,
);
let color: Srgb<f32> = Srgb::from_color_unclamped(color);
Color::Rgb(
(color.red * 255.0) as u8,
(color.green * 255.0) as u8,
(color.blue * 255.0) as u8,
)
}
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 random_color () -> Color {
okhsl_to_rgb(random_okhsl())
}
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)
@ -64,17 +67,7 @@ pub fn random_color_near (color: Color, distance: f32) -> Color {
g as f32 / 255.0,
b as f32 / 255.0,
]);
let mut rng = thread_rng();
let new: Okhsl<f32> = Okhsl::new(
rng.gen::<f32>() * 360f32 - 180f32,
rng.gen::<f32>(),
rng.gen::<f32>() * 0.66,
);
let new: Okhsl<f32> = random_okhsl();
let mixed = new.mix(old, 0.5);
let color: Srgb<f32> = Srgb::from_color_unclamped(mixed);
Color::Rgb(
(color.red * 255.0) as u8,
(color.green * 255.0) as u8,
(color.blue * 255.0) as u8,
)
okhsl_to_rgb(mixed)
}