Parent

Fractals::Renderers::Base

Inherited by Fractal, Renderers::Base includes traits common to each of the rendering modules.

Attributes

bailout[RW]

The number that determines if an iteration is approaching inifinity.

max_iterations[RW]

The maximum number of iterations to perform on an expression.

last_iteration[RW]

The last iteration number of a complex coordinate. Determined by the in_set? method.

algorithm[RW]

The renderer’s coloring algorithm.

width[RW]

The width of the fractal image.

height[RW]

The height of the fractal image.

magnification[RW]

The magnification level of the fractal in powers of 100.

theme[RW]

The coloring theme applied to complex coordinates that lie outside of the fractal set.

set_color[RW]

The color of complex coordinates inside the fractal set. Expects an array of RGB values [R, G, B].

Public Class Methods

acts_as_renderer(renderer) click to toggle source

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
new(bailout=2, max_iterations=50, algorithm=Algorithms::EscapeTime) click to toggle source

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

Public Instance Methods

in_set?(c) click to toggle source

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
render() click to toggle source

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
renderer=(renderer) click to toggle source

Extends the Renderers::Base class with the provided module.

Example:

mandelbrot = Mandelbrot.new
mandelbrot.renderer = Renderers::RMagickRenderer

# File lib/fractals/renderers.rb, line 75
      def renderer=(renderer)
        self.extend renderer
      end
where_is?(x, y) click to toggle source

Determines the location of an x, y value pair on the complex coordinate plane.

# File lib/fractals/renderers.rb, line 87
      def where_is?(x, y)
        Complex(@c.real - (@width / 2 * scale) + (x * scale),
                  @c.image - (@height / 2 * scale) + (y * scale))
      end

Private Instance Methods

scale() click to toggle source

(Not documented)

# File lib/fractals/renderers.rb, line 93
      def scale
        0.01 / @magnification
      end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.