readded progressbar
This commit is contained in:
@@ -9,3 +9,4 @@ edition = "2021"
|
||||
rand = "0.7.0"
|
||||
rayon = "1.8"
|
||||
image = "0.25.9"
|
||||
indicatif = "0.18.3"
|
||||
19
src/main.rs
19
src/main.rs
@@ -9,6 +9,7 @@ pub mod sphere;
|
||||
pub mod vec3;
|
||||
|
||||
use image::{Pixel, RgbImage};
|
||||
use indicatif::{ProgressBar, ProgressStyle};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
@@ -143,6 +144,18 @@ fn main() {
|
||||
|
||||
let mut img_buffer = RgbImage::new(image_width as u32, image_height as u32);
|
||||
|
||||
let total_pixels = (image_width * image_height) as u64;
|
||||
let bar = ProgressBar::new(total_pixels);
|
||||
|
||||
bar.set_style(
|
||||
ProgressStyle::default_bar()
|
||||
.template(
|
||||
"{spinner:.green} [{elapsed_precise}] [{bar:40.green/black}] {percent}% ({eta})",
|
||||
)
|
||||
.unwrap()
|
||||
.progress_chars("#>-"),
|
||||
);
|
||||
|
||||
img_buffer
|
||||
.par_enumerate_pixels_mut()
|
||||
.for_each(|(x, y, pixel)| {
|
||||
@@ -162,8 +175,14 @@ fn main() {
|
||||
pixel.channels_mut()[0] = ir;
|
||||
pixel.channels_mut()[1] = ig;
|
||||
pixel.channels_mut()[2] = ib;
|
||||
|
||||
bar.inc(1);
|
||||
});
|
||||
|
||||
bar.finish_with_message("Render Complete!");
|
||||
|
||||
img_buffer.save("render.png").unwrap();
|
||||
}
|
||||
|
||||
// print!("\r{} %", progress);
|
||||
// let _ = stdout().flush();
|
||||
|
||||
Reference in New Issue
Block a user