| Class | Fractals::Renderers::Base |
| In: |
lib/fractals/renderers.rb
|
| Parent: | Object |
Inherited by Fractal, Renderers::Base includes traits common to each of the rendering modules.
| algorithm | [RW] | The renderer’s coloring algorithm. |
| bailout | [RW] | The number that determines if an iteration is approaching inifinity. |
| height | [RW] | The height of the fractal image. |
| last_iteration | [RW] | The last iteration number of a complex coordinate. Determined by the in_set? method. |
| magnification | [RW] | The magnification level of the fractal in powers of 100. |
| max_iterations | [RW] | The maximum number of iterations to perform on an expression. |
| set_color | [RW] | The color of complex coordinates inside the fractal set. Expects an array of RGB values [R, G, B]. |
| theme | [RW] | The coloring theme applied to complex coordinates that lie outside of the fractal set. |
| width | [RW] | The width of the fractal image. |
Includes the provided module. Use the renderer= method for setting the renderer at runtime.
# File lib/fractals/renderers.rb, line 81 def self.acts_as_renderer(renderer) include renderer end
Sets the default property values.
# File lib/fractals/renderers.rb, line 36 def initialize(bailout=2, max_iterations=50, algorithm=Algorithms::EscapeTime) @bailout, @max_iterations = bailout, max_iterations @algorithm = algorithm @width, @height = 300, 300 @magnification = 1.0 @theme, @set_color = Themes::Fire, [0, 0, 0] end
Determines if a complex coordinate lies within the fractal’s set.
# File lib/fractals/renderers.rb, line 45 def in_set?(c) @args[:c] = c iterate(@max_iterations) do |i, z| if z.abs > @bailout then @last_iteration = i return false end end return true end
Loops through each x, y value pair yielding the pair and its RGB color value as an array [R, G, B].
# File lib/fractals/renderers.rb, line 58 def render (0...@width).each do |x| (0...@height).each do |y| if !in_set?(where_is?(x, y)) then yield x, y, @theme.call(@algorithm.call(self)) else yield x, y, @set_color end end end end
Extends the Renderers::Base class with the provided module.
mandelbrot = Mandelbrot.new
mandelbrot.renderer = Renderers::RMagickRenderer
# File lib/fractals/renderers.rb, line 75 def renderer=(renderer) self.extend renderer end