aboutsummaryrefslogtreecommitdiff
path: root/lib/ray.rb
diff options
context:
space:
mode:
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