Skip to content

Commit 31c19d2

Browse files
committed
chapter 11, 12, 13 api cleanup
1 parent 18c510c commit 31c19d2

File tree

19 files changed

+90056
-90093
lines changed

19 files changed

+90056
-90093
lines changed

08.5/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
let ray = camera.ray(u, v);
4545
pixel_color = pixel_color + ray.color_08_5(&world, max_depth, &mut rng);
4646
}
47-
write_color(&output, pixel_color, samples_per_pixel, false);
47+
write_color(&output, pixel_color, samples_per_pixel, true);
4848
}
4949
}
5050
println!("DONE")

08.6/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn main() {
4444
let ray = camera.ray(u, v);
4545
pixel_color = pixel_color + ray.color_08_6(&world, max_depth, &mut rng);
4646
}
47-
write_color(&output, pixel_color, samples_per_pixel, false);
47+
write_color(&output, pixel_color, samples_per_pixel, true);
4848
}
4949
}
5050
println!("DONE")

09.5/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
let ray = camera.ray(u, v);
7171
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
7272
}
73-
write_color(&output, pixel_color, samples_per_pixel, false);
73+
write_color(&output, pixel_color, samples_per_pixel, true);
7474
}
7575
}
7676
println!("DONE")

09.6/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
let ray = camera.ray(u, v);
7171
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
7272
}
73-
write_color(&output, pixel_color, samples_per_pixel, false);
73+
write_color(&output, pixel_color, samples_per_pixel, true);
7474
}
7575
}
7676
println!("DONE")

10.3/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn main() {
6666
let ray = camera.ray(u, v);
6767
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
6868
}
69-
write_color(&output, pixel_color, samples_per_pixel, false);
69+
write_color(&output, pixel_color, samples_per_pixel, true);
7070
}
7171
}
7272
println!("DONE")

10.4/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn main() {
6666
let ray = camera.ray(u, v);
6767
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
6868
}
69-
write_color(&output, pixel_color, samples_per_pixel, false);
69+
write_color(&output, pixel_color, samples_per_pixel, true);
7070
}
7171
}
7272
println!("DONE")

10.5/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn main() {
7272
let ray = camera.ray(u, v);
7373
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
7474
}
75-
write_color(&output, pixel_color, samples_per_pixel, false);
75+
write_color(&output, pixel_color, samples_per_pixel, true);
7676
}
7777
}
7878
println!("DONE")

11.1/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11.1/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2018"
77

88
[dependencies]
99
raylib = { path = "../raylib" }
10+
rand = "0.8.4"

11.1/src/main.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
extern crate raylib;
22

3+
use rand::prelude::*;
34
use raylib::{
45
camera::Camera, file::File, hittable::Hittables, lambertian::Lambertian, random,
5-
random_unit_vector, sphere::Sphere, vec::Vec3, write_color,
6+
sphere::Sphere, vec::Vec3, write_color,
67
};
78

89
fn main() {
10+
let mut rng = thread_rng();
11+
912
// image
1013
let aspect_ratio = 16.0 / 9.0;
1114
let width = 400;
@@ -15,15 +18,11 @@ fn main() {
1518
println!("image h {} w {}", height, width);
1619

1720
// camera
18-
let camera = Camera::with_vfov(90.0, aspect_ratio);
21+
let camera = Camera::new11_1(90.0, aspect_ratio);
1922

2023
// world
21-
let left = Lambertian {
22-
albedo: Vec3::new(0.0, 0.0, 1.0),
23-
};
24-
let right = Lambertian {
25-
albedo: Vec3::new(1.0, 0.0, 0.0),
26-
};
24+
let left = Lambertian::new(Vec3::new(0.0, 0.0, 1.0));
25+
let right = Lambertian::new(Vec3::new(1.0, 0.0, 0.0));
2726

2827
let mut world: Hittables = Hittables {
2928
list: std::vec::Vec::new(),
@@ -49,19 +48,12 @@ fn main() {
4948
for w in 0..width {
5049
let mut pixel_color = Vec3::new(0.0, 0.0, 0.0);
5150
for _ in 0..samples_per_pixel {
52-
let u: f64 = (w as f64 + random()) / (width as f64 - 1.0);
53-
let v: f64 = (h as f64 + random()) / (height as f64 - 1.0);
51+
let u: f64 = (w as f64 + random(&mut rng)) / (width as f64 - 1.0);
52+
let v: f64 = (h as f64 + random(&mut rng)) / (height as f64 - 1.0);
5453
let ray = camera.ray(u, v);
55-
let world_hit_t_min = 0.001;
56-
pixel_color = pixel_color
57-
+ ray.diffused_world_color(
58-
&world,
59-
max_depth,
60-
world_hit_t_min,
61-
random_unit_vector,
62-
);
54+
pixel_color = pixel_color + ray.color_09_4(&world, max_depth, &mut rng);
6355
}
64-
write_color(&output, pixel_color, samples_per_pixel, false);
56+
write_color(&output, pixel_color, samples_per_pixel, true);
6557
}
6658
}
6759
println!("DONE")

0 commit comments

Comments
 (0)