raytracing-rs

https://raytracing.github.io in Rust

git clone https://code.pdelong.com/raytracing-rs.git

 1#![allow(dead_code)]
 2
 3mod camera;
 4mod hittable;
 5mod math;
 6
 7use camera::CameraBuilder;
 8use hittable::HittableList;
 9use hittable::Sphere;
10use math::Point;
11
12fn main() {
13    let mut camera = CameraBuilder::new()
14        .aspect_ratio(16. / 10.)
15        .image_width(1024)
16        .samples_per_pixel(1024)
17        .max_depth(10)
18        .build();
19
20    let mut world = HittableList::new();
21    world.push(Box::new(Sphere::new(
22        Point {
23            x: 0.,
24            y: 0.,
25            z: -1.,
26        },
27        0.5,
28    )));
29
30    world.push(Box::new(Sphere::new(
31        Point {
32            x: 0.,
33            y: -100.5,
34            z: -1.,
35        },
36        100.,
37    )));
38
39    let f = std::fs::File::create("image.ppm").unwrap();
40    let w = std::io::BufWriter::new(f);
41
42    camera.render(w, world);
43}