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, depth) return Colour.new if depth <= 0 if rec = world.hit(self, Interval.new(0.0001, Float::INFINITY)) dir = Vec3.random_unit(rec.normal) return Ray.new(rec.point, dir).colour(world, depth - 1) * 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