diff options
author | Nat Lasseter <user@4574.co.uk> | 2024-06-12 21:26:19 +0100 |
---|---|---|
committer | Nat Lasseter <user@4574.co.uk> | 2024-06-12 21:26:19 +0100 |
commit | 51416f5dfac39b6ede8340b57b9bed4eb3edc646 (patch) | |
tree | fa840f778dd5a48bc915dd43609d5065b5e1d115 /lib/ray.rb | |
parent | df7c4a808d691e1d927047bb86aa9738780e694d (diff) |
Done Chapter 8
Diffstat (limited to 'lib/ray.rb')
-rw-r--r-- | lib/ray.rb | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -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 |