ft: 3: vec3 class

This commit is contained in:
2026-04-15 00:17:57 +02:00
parent 1c7460d2f5
commit 8e96a0ba11
5 changed files with 922 additions and 12 deletions

View File

@@ -1,7 +1,13 @@
#![feature(core_float_math)]
mod vec3;
use crate::vec3::Vec3;
use log::info;
use pretty_env_logger;
fn main() {
let v = Vec3::rgb(255., 0., 255.);
pretty_env_logger::init();
let image_width = 256;
@@ -12,16 +18,14 @@ fn main() {
for j in 0..image_height {
info!("{}\tScanlines remaining.", (image_height - j));
for i in 0..image_width {
let r = i as f32 / (image_width - 1) as f32;
let g = j as f32 / (image_height - 1) as f32;
let b = 0.0;
let ir = (255.599 * r) as u8;
let ig = (255.599 * g) as u8;
let ib = (255.599 * b) as u8;
let rgb = Vec3::rgb(
i as f32 / (image_width - 1) as f32,
j as f32 / (image_height - 1) as f32,
0.0,
);
let pixel = imgbuf.get_pixel_mut(i, j);
*pixel = image::Rgb([ir, ig, ib]);
*pixel = rgb.output();
}
}