Skip to content

Commit

Permalink
Print progress to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
jstasiak committed Jul 10, 2019
1 parent 23696aa commit f8a2520
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Binary file modified output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/lib.rs
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f8a2520

Please sign in to comment.