more cleanup
This commit is contained in:
10
src/color.rs
10
src/color.rs
@@ -1,6 +1,8 @@
|
||||
use crate::{vec3::*, rtweekend::clamp};
|
||||
use image::Rgb;
|
||||
|
||||
pub fn get_scaled_color_components(c: Color, samples_per_pixel: i32) -> (u8, u8, u8) {
|
||||
use crate::{rtweekend::clamp, vec3::*};
|
||||
|
||||
pub fn get_scaled_color_components(c: Color, samples_per_pixel: i32) -> Rgb<u8> {
|
||||
let r = c.x();
|
||||
let g = c.y();
|
||||
let b = c.z();
|
||||
@@ -11,9 +13,9 @@ pub fn get_scaled_color_components(c: Color, samples_per_pixel: i32) -> (u8, u8,
|
||||
let g = (scale * g).sqrt();
|
||||
let b = (scale * b).sqrt();
|
||||
|
||||
(
|
||||
Rgb([
|
||||
(255.0 * clamp(r, 0.0, 1.0)) as u8,
|
||||
(255.0 * clamp(g, 0.0, 1.0)) as u8,
|
||||
(255.0 * clamp(b, 0.0, 1.0)) as u8,
|
||||
)
|
||||
])
|
||||
}
|
||||
12
src/main.rs
12
src/main.rs
@@ -179,10 +179,10 @@ fn three_balls_scene(aspect_ratio: f64) -> (Camera, HittableList) {
|
||||
fn main() {
|
||||
// Image
|
||||
let aspect_ratio: f64 = 16. / 9.;
|
||||
let image_width: i32 = 1920;
|
||||
let image_width: i32 = 500;
|
||||
let image_height: i32 = (image_width as f64 / aspect_ratio as f64) as i32;
|
||||
let samples_per_pixel: i32 = 200;
|
||||
let max_depth: i32 = 10;
|
||||
let samples_per_pixel: i32 = 50;
|
||||
let max_depth: i32 = 4;
|
||||
|
||||
let (cam, world) = random_scene(aspect_ratio);
|
||||
|
||||
@@ -225,11 +225,7 @@ fn main() {
|
||||
pixel_color += cam.ray_color(r, &world, max_depth);
|
||||
}
|
||||
|
||||
let (ir, ig, ib) = get_scaled_color_components(pixel_color, samples_per_pixel);
|
||||
|
||||
pixel.channels_mut()[0] = ir;
|
||||
pixel.channels_mut()[1] = ig;
|
||||
pixel.channels_mut()[2] = ib;
|
||||
*pixel = get_scaled_color_components(pixel_color, samples_per_pixel);
|
||||
|
||||
bar.inc(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user