diff --git a/rtiow/src/bin/tracer1.rs b/rtiow/src/bin/tracer1.rs new file mode 100644 index 0000000..d584e50 --- /dev/null +++ b/rtiow/src/bin/tracer1.rs @@ -0,0 +1,33 @@ +extern crate rtiow; + +use rtiow::ray::Ray; +use rtiow::vec3::Vec3; + +fn color(r: Ray) -> Vec3 { + let unit_direction = r.direction().unit_vector(); + let t = 0.5 * (unit_direction.y + 1.); + Vec3::new(1., 1., 1.) * (1. - t) + Vec3::new(0.5, 0.7, 1.) * t +} + +fn main() -> Result<(), std::io::Error> { + let nx = 200; + let ny = 100; + println!("P3\n{} {}\n255", nx, ny); + let lower_left_corner = Vec3::new(-2., -1., -1.); + let horizontal = Vec3::new(4., 0., 0.); + let vertical = Vec3::new(0., 2., 0.); + let origin: Vec3 = Default::default(); + for j in (0..ny).rev() { + for i in 0..nx { + let u = i as f32 / nx as f32; + let v = j as f32 / ny as f32; + let r = Ray::new(origin, lower_left_corner + horizontal * u + vertical * v); + let col = color(r); + let ir = (255.99 * col[0]) as u32; + let ig = (255.99 * col[1]) as u32; + let ib = (255.99 * col[2]) as u32; + println!("{} {} {}", ir, ig, ib); + } + } + Ok(()) +}