aboutsummaryrefslogtreecommitdiff
path: root/lib/ray.rb
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2024-06-12 21:26:19 +0100
committerNat Lasseter <user@4574.co.uk>2024-06-12 21:26:19 +0100
commit51416f5dfac39b6ede8340b57b9bed4eb3edc646 (patch)
treefa840f778dd5a48bc915dd43609d5065b5e1d115 /lib/ray.rb
parentdf7c4a808d691e1d927047bb86aa9738780e694d (diff)
Done Chapter 8
Diffstat (limited to 'lib/ray.rb')
-rw-r--r--lib/ray.rb10
1 files changed, 10 insertions, 0 deletions
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