Class: Ra::Engine
Overview
An engine takes a world / camera and generates a PPM.
Constant Summary collapse
- PRECISION =
255
- PORCESSES =
8
- PPM_VERSION =
'P3'
- PPM_DEFAULT =
'0 0 0'
Instance Method Summary collapse
- #each {|pixel| ... } ⇒ Object
-
#initialize(world:, camera:) ⇒ Engine
constructor
A new instance of Engine.
- #ppm {|text| ... } ⇒ Object
Constructor Details
#initialize(world:, camera:) ⇒ Engine
Returns a new instance of Engine.
16 17 18 19 |
# File 'lib/ra/engine.rb', line 16 def initialize(world:, camera:) @world = world @camera = camera end |
Instance Method Details
#each {|pixel| ... } ⇒ Object
23 24 25 26 27 28 |
# File 'lib/ra/engine.rb', line 23 def each @camera.each do |y, x, ray| color = @world.color(ray:) yield(Ra::Pixel.new(x:, y:, color:)) end end |
#ppm {|text| ... } ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ra/engine.rb', line 32 def ppm yield(<<~PPM) #{PPM_VERSION} #{@camera.w} #{@camera.h} #{Color::PRECISION} PPM each do |pixel| yield(pixel.color ? pixel.color.ppm : PPM_DEFAULT) end end |