class Ray def initialize(origin = Point.new, direction = Vec3.new) @origin = origin @direction = direction end attr_reader :origin, :direction 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