From f8a2520388c504d7c48c04f23dca3031a8dc8d94 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Wed, 10 Jul 2019 18:01:53 +0200 Subject: [PATCH] Print progress to stderr --- output.png | Bin 84618 -> 84618 bytes src/lib.rs | 9 +++++++++ 2 files changed, 9 insertions(+) diff --git a/output.png b/output.png index 1793ca157ffa0f0a171b6dc0862525fd06e67ba1..fa7aaf7d87ae7a74e4072012c55e7a5cad7c54ae 100644 GIT binary patch delta 64 zcmeC0%Gx!RwP6dRjhCRAm4Ts^iJ7*6ft7)Qj)ig1bYCw<1z8l~*wpTK3_#%N>gTe~ HDWM4fBwG;6 delta 64 zcmeC0%Gx!RwP6dRjhCRQm5GU!v4ysQft7*5+#gfrru%v^D#)S;zgeoghye&ZUHx3v IIVCg!0A8aKT>t<8 diff --git a/src/lib.rs b/src/lib.rs index ba6731a..03af09d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -351,6 +351,9 @@ pub fn render( bounces: usize, ) -> Image { let mut image = Image::new(width, height); + let pixels_total = width * height; + let mut pixels_done = 0; + let mut percent = 0; for i in 0..width { for j in 0..height { // -1s here because we want to provide x and y coordinates between 0 and 1 inclusive @@ -360,6 +363,12 @@ pub fn render( ); let color = trace_ray(&spheres, &ray, bounces); image.set_color(i, j, color); + pixels_done += 1; + let new_percent = pixels_done * 100 / pixels_total; + if new_percent != percent { + eprintln!("{}% done...", new_percent); + percent = new_percent; + } } } image