#![feature(portable_simd)]

use raytracer::{random_f64, random_f64_range, Raytracer};
use vec3::{Color, Point3};

pub mod builder;
pub mod hittable;
pub mod interval;
pub mod material;
pub mod out;
pub mod ray;
pub mod raytracer;
pub mod vec3;

pub fn cover(width: usize, height: usize, spp: usize) -> Raytracer {
	let mut builder = Raytracer::builder()
		.image_size(width, height)
		.samples_per_pixel(spp)
		.max_depth(50)
		.vertical_fov(20.0)
		.look_from(13.0, 2.0, 3.0)
		.look_at(0.0, 0.0, 0.0)
		.vup(0.0, 1.0, 0.0)
		.defocus_angle(0.6)
		.focus_dist(10.0)
		.with_sphere(0.0, -1000.0, 0.0, 1000.0)
		.lambertian(1.0, 0.6, 0.7);

	for a in -11..11 {
		for b in -11..11 {
			let choose_mat = random_f64();
			let center =
				Point3::new(a as f64 + 0.9 * random_f64(), 0.2, b as f64 + 0.9 * random_f64());

			if (center - Point3::new(4.0, 0.2, 0.0)).len() > 0.9 {
				let shape_builder = builder.with_sphere(center.x(), center.y(), center.z(), 0.2);

				builder = if choose_mat < 0.8 {
					let albedo = Color::random() * Color::random();
					shape_builder.lambertian(albedo.r(), albedo.g(), albedo.b())
				} else if choose_mat < 0.95 {
					let albedo = Color::random_range(0.5, 1.0);
					let fuzz = random_f64_range(0.0, 0.5);
					shape_builder.metal(albedo.r(), albedo.g(), albedo.b(), fuzz)
				} else {
					shape_builder.dielectric(1.5)
				};
			}
		}
	}

	builder
		.with_sphere(0.0, 1.0, 0.0, 1.0)
		.dielectric(1.5)
		.with_sphere(-4.0, 1.0, 0.0, 1.0)
		.lambertian(1.0, 0.5, 0.6)
		.with_sphere(4.0, 1.0, 0.0, 1.0)
		.metal(0.7, 0.6, 0.5, 0.0)
		.finish()
}
