From 78ddaff5855bf8446adef9e18eb0d7b7ddcee52a Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:45:56 +0000 Subject: init --- src/texture/checker_texture.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/texture/checker_texture.rs (limited to 'src/texture/checker_texture.rs') diff --git a/src/texture/checker_texture.rs b/src/texture/checker_texture.rs new file mode 100644 index 0000000..385017b --- /dev/null +++ b/src/texture/checker_texture.rs @@ -0,0 +1,29 @@ +use std::sync::Arc; + +use super::{Texture, SolidColor}; +use crate::{vec3::Color, vec3::Point3}; + +pub struct CheckerTexture { + odd: Arc, + even: Arc, +} + +impl CheckerTexture { + pub fn from_colors(odd: Color, even: Color) -> Self { + Self { + odd: Arc::new(SolidColor::from_color(odd)), + even: Arc::new(SolidColor::from_color(even)), + } + } +} + +impl Texture for CheckerTexture { + fn value(&self, u: f64, v: f64, p: &Point3) -> Color { + let sines = (10.0 * p.x).sin() * (10.0 * p.y).sin() * (10.0 * p.z).sin(); + if sines < 0.0 { + self.odd.value(u, v, p) + } else { + self.even.value(u, v, p) + } + } +} -- cgit v1.2.3