use prismatica::Color;
use prismatica::matplotlib::VIRIDIS;
use slint::Color as SlintColor;
fn main() {
let cm = &VIRIDIS;
let n = 8;
println!("Colormap: {} ({})\n", cm.meta.name, cm.meta.collection);
println!(
" {:<4} {:>3} {:>3} {:>3} slint Color (u8 accessors)",
"i", "R", "G", "B"
);
println!(" {}", "-".repeat(52));
for i in 0..n {
let color = cm.eval_rational(i, n);
let slint_c: SlintColor = color.into();
assert_eq!(slint_c.red(), color.r, "red mismatch at index {i}");
assert_eq!(slint_c.green(), color.g, "green mismatch at index {i}");
assert_eq!(slint_c.blue(), color.b, "blue mismatch at index {i}");
let back: Color = slint_c.into();
let swatch = format!("\x1b[48;2;{};{};{}m \x1b[0m", color.r, color.g, color.b);
println!(
" {:<4} {:>3} {:>3} {:>3} red={:>3} green={:>3} blue={:>3} {}",
i,
color.r,
color.g,
color.b,
slint_c.red(),
slint_c.green(),
slint_c.blue(),
swatch
);
assert_eq!(color, back, "round-trip failed at index {i}");
}
println!("\nAll {n} samples round-tripped losslessly through slint::Color.");
}