1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
use colorgrad::Gradient;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let width = 1300.0;
let height = 70.0;
// preset gradient
let grad = colorgrad::preset::rainbow();
let imgbuf = image::ImageBuffer::from_fn(width as u32, height as u32, |x, _| {
image::Rgba(grad.at(x as f32 / width).to_rgba8())
});
imgbuf.save("gradient-preset.png")?;
// custom gradient
let grad = colorgrad::GradientBuilder::new()
.html_colors(&["deeppink", "gold", "seagreen"])
.build::<colorgrad::CatmullRomGradient>()?;
let imgbuf = image::ImageBuffer::from_fn(width as u32, height as u32, |x, _| {
image::Rgba(grad.at(x as f32 / width).to_rgba8())
});
imgbuf.save("gradient-custom.png")?;
Ok(())
}
|