use image::RgbImage;
use prismatica::Color;
use prismatica::matplotlib::VIRIDIS;
use tiny_skia::Color as SkiaColor;
fn main() {
let cm = &VIRIDIS;
let width = 512u32;
let height = 64u32;
println!("Colormap: {} ({})", cm.meta.name, cm.meta.collection);
println!("Rendering {}x{} gradient...\n", width, height);
let mut pixmap = tiny_skia::Pixmap::new(width, height).expect("failed to create pixmap");
for x in 0..width {
let t = x as f32 / (width - 1) as f32;
let color = cm.eval(t);
let skia: SkiaColor = color.into();
let _back: Color = skia.into();
let premul = skia.premultiply().to_color_u8();
for y in 0..height {
let idx = (y * width + x) as usize;
pixmap.pixels_mut()[idx] = premul;
}
}
let mut img = RgbImage::new(width, height);
for y in 0..height {
for x in 0..width {
let t = x as f32 / (width - 1) as f32;
let color = cm.eval(t);
let pixel: image::Rgb<u8> = color.into();
img.put_pixel(x, y, pixel);
}
}
let filename = "viridis_tiny_skia_gradient.png";
img.save(filename).expect("failed to save PNG");
println!("Saved {}", filename);
print!(" ");
for i in 0..64 {
let t = i as f32 / 63.0;
let c = cm.eval(t);
print!("\x1b[48;2;{};{};{}m \x1b[0m", c.r, c.g, c.b);
}
println!();
}