3 releases
0.1.2 | Nov 20, 2022 |
---|---|
0.1.1 | Nov 20, 2022 |
0.1.0 | Nov 20, 2022 |
#13 in #ppm
15KB
95 lines
ppmwriter
Usage
use std::fs::File;
use std::io::Write;
use std::path::Path;
use ppmwriter::Writer;
fn main() {
let name = "image.ppm";
let mut ppm = Writer::new(69, 35, 2301).unwrap();
for n in 0..ppm.size {
if n % 2 == 0 {
ppm.write_pixel(ppm.maxval, 0, ppm.maxval);
} else {
ppm.write_pixel(0, 0, 0);
}
}
let path = Path::new(name);
let mut file = match File::create(path) {
Err(why) => panic!("Couldn't create {}: {}", path.display(), why),
Ok(file) => file,
};
if let Err(why) = file.write_all(ppm.borrow_buffer()) {
panic!("Couldn't write to {}: {}", path.display(), why)
}
}