From 51416f5dfac39b6ede8340b57b9bed4eb3edc646 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Wed, 12 Jun 2024 21:26:19 +0100 Subject: Done Chapter 8 --- lib/ray.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/ray.rb') diff --git a/lib/ray.rb b/lib/ray.rb index 4d282cb..47f2b26 100644 --- a/lib/ray.rb +++ b/lib/ray.rb @@ -9,4 +9,14 @@ class Ray def at(time) @origin + (@direction * time) end + + def colour(world) + if rec = world.hit(self, Interval.new(0, Float::INFINITY)) + return (Colour.new(1,1,1) + rec.normal) * 0.5 + end + + unit_dir = direction.unit + a = (unit_dir.y + 1) / 2 + Colour.new(1.0, 1.0, 1.0) * (1-a) + Colour.new(0.5, 0.7, 1.0) * a + end end -- cgit v1.2.1