bitart: Use saturated colors

This commit is contained in:
Juergen Stuber
2026-03-17 21:44:09 +01:00
parent 1229b19ca3
commit 24c74512ff

View File

@@ -22,15 +22,19 @@ use expression::RandomExpressionBuilder;
use expression::Variable; use expression::Variable;
fn random_color<R: Rng>(rng: &mut R) -> Color { fn random_color<R: Rng>(rng: &mut R) -> Color {
let r = rng.random::<f64>(); let a = 255;
let g = rng.random::<f64>(); let b = rng.random::<u8>();
let b = rng.random::<f64>(); let c = 0;
let s = r + g + b; let (r, g, b) = match rng.random_range(0..6) {
0 => (a, b, c),
let r = (255.0 * r / s) as u8; 1 => (a, c, b),
let g = (255.0 * g / s) as u8; 2 => (b, a, c),
let b = (255.0 * b / s) as u8; 3 => (b, c, a),
4 => (c, a, b),
5 => (c, b, a),
_ => unreachable!(),
};
Color::new(r, g, b) Color::new(r, g, b)
} }