From 44f8803f416efa11be910a577ab3e40cfb2433b0 Mon Sep 17 00:00:00 2001 From: plexx-dev Date: Wed, 18 Feb 2026 21:49:23 +0100 Subject: [PATCH] more cleanup --- src/color.rs | 12 +++++++----- src/main.rs | 12 ++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/color.rs b/src/color.rs index ca75f58..1b96fb2 100644 --- a/src/color.rs +++ b/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 { 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, - ) -} \ No newline at end of file + ]) +} diff --git a/src/main.rs b/src/main.rs index b90d6b5..5fa10f5 100644 --- a/src/main.rs +++ b/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); });