First tries with pixel_color
This commit is contained in:
parent
64f46fb251
commit
1cb4defeba
3 changed files with 1091 additions and 6 deletions
1080
Cargo.lock
generated
1080
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
image = { version = "0.24.2", default-features = false, features = ["jpeg", "png", "pnm"] }
|
image = { version = "0.24.2", default-features = false, features = ["jpeg", "png", "pnm"] }
|
||||||
indicatif = "0.17.0"
|
indicatif = "0.17.0"
|
||||||
|
pixel-canvas = "0.2.3"
|
||||||
rand = { version = "0.8.5", features = ["small_rng"] }
|
rand = { version = "0.8.5", features = ["small_rng"] }
|
||||||
rayon = "1.5.3"
|
rayon = "1.5.3"
|
||||||
tobj = "3.2.3"
|
tobj = "3.2.3"
|
||||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -15,6 +15,7 @@ use hittable_list::HittableList;
|
||||||
use image::{Rgb, RgbImage};
|
use image::{Rgb, RgbImage};
|
||||||
use indicatif::ProgressBar;
|
use indicatif::ProgressBar;
|
||||||
use material::{Dielectric, Lambertian, Material, Metal, Rainbow};
|
use material::{Dielectric, Lambertian, Material, Metal, Rainbow};
|
||||||
|
use pixel_canvas::{Canvas, Color as canvColor, RC};
|
||||||
use ray::Ray;
|
use ray::Ray;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -102,6 +103,11 @@ fn main() {
|
||||||
dist_to_focus,
|
dist_to_focus,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Canvas
|
||||||
|
let canvas = Canvas::new(image_width as usize, image_height as usize)
|
||||||
|
.title("Raytracer");
|
||||||
|
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
let args: Vec<String> = env::args().collect();
|
let args: Vec<String> = env::args().collect();
|
||||||
if args.len() > 1 && args[1] != "" {
|
if args.len() > 1 && args[1] != "" {
|
||||||
|
@ -131,6 +137,16 @@ fn main() {
|
||||||
max_depth,
|
max_depth,
|
||||||
);
|
);
|
||||||
colors.push(pixel_color);
|
colors.push(pixel_color);
|
||||||
|
canvas.render(
|
||||||
|
|mouse, image| {
|
||||||
|
let addr = RC{0: j as usize, 1: i as usize};
|
||||||
|
image[addr] = canvColor {
|
||||||
|
r: pixel_color.x() as u8,
|
||||||
|
g: pixel_color.y() as u8,
|
||||||
|
b: pixel_color.z() as u8,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return colors;
|
return colors;
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue