nullgeo-cli 0.1.1

Command-line ray tracer for null geodesics in arbitrary spacetimes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::fs::File;
use std::io::{BufWriter, Write};

pub fn write_ppm_gray(path: &str, width: usize, height: usize, pixels: &[u8]) -> std::io::Result<()> {
    if pixels.len() != width*height {
        return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, "pixel buffer size mismatch"));
    }
    let mut f = BufWriter::new(File::create(path)?);
    writeln!(f, "P5")?;
    writeln!(f, "{} {}", width, height)?;
    writeln!(f, "255")?;
    f.write_all(pixels)?;
    Ok(())
}