more cleanup

This commit is contained in:
2026-02-18 21:49:23 +01:00
parent bff7c79abd
commit 44f8803f41
2 changed files with 11 additions and 13 deletions

View File

@@ -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,
)
}
])
}

View File

@@ -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);
});