From 3dfd71282b1580431967faa819dc457ca0932ec6 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sat, 8 Sep 2018 17:32:12 -0700 Subject: [PATCH] simple_ppm writer. --- rtiow/Cargo.lock | 4 ++++ rtiow/Cargo.toml | 6 ++++++ rtiow/README.md | 3 +++ rtiow/src/bin/simple_ppm.rs | 18 ++++++++++++++++++ rtiow/src/lib.rs | 7 +++++++ 5 files changed, 38 insertions(+) create mode 100644 rtiow/Cargo.lock create mode 100644 rtiow/Cargo.toml create mode 100644 rtiow/README.md create mode 100644 rtiow/src/bin/simple_ppm.rs create mode 100644 rtiow/src/lib.rs diff --git a/rtiow/Cargo.lock b/rtiow/Cargo.lock new file mode 100644 index 0000000..745b43f --- /dev/null +++ b/rtiow/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "rtiow" +version = "0.1.0" + diff --git a/rtiow/Cargo.toml b/rtiow/Cargo.toml new file mode 100644 index 0000000..f469874 --- /dev/null +++ b/rtiow/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "rtiow" +version = "0.1.0" +authors = ["Bill Thiede "] + +[dependencies] diff --git a/rtiow/README.md b/rtiow/README.md new file mode 100644 index 0000000..86d83ee --- /dev/null +++ b/rtiow/README.md @@ -0,0 +1,3 @@ +# What? +Implementations of the concepts explored by Peter Shirley in "Ray Tracing in +One Weekend" diff --git a/rtiow/src/bin/simple_ppm.rs b/rtiow/src/bin/simple_ppm.rs new file mode 100644 index 0000000..3ba3eb7 --- /dev/null +++ b/rtiow/src/bin/simple_ppm.rs @@ -0,0 +1,18 @@ +fn main() -> Result<(), std::io::Error> { + let nx = 200; + let ny = 100; + println!("P3\n{} {}\n255", nx, ny); + for j in (0..ny).rev() { + for i in 0..nx { + let r = i as f32 / nx as f32; + let g = j as f32 / ny as f32; + let b = 0.2; + + let ir = (255.99 * r) as u8; + let ig = (255.99 * g) as u8; + let ib = (255.99 * b) as u8; + println!("{} {} {}", ir, ig, ib); + } + } + Ok(()) +} diff --git a/rtiow/src/lib.rs b/rtiow/src/lib.rs new file mode 100644 index 0000000..31e1bb2 --- /dev/null +++ b/rtiow/src/lib.rs @@ -0,0 +1,7 @@ +#[cfg(test)] +mod tests { + #[test] + fn it_works() { + assert_eq!(2 + 2, 4); + } +}