Module: Fractals::Algorithms

Defined in:
lib/fractals/algorithms.rb

Overview

A renderer’s algorithm calculates the color index for complex coordinates that lie outside of a fractal’s set.

EscapeTime

The default algorithm for orbits fractals.

NormalizedIterationCount

Produces an image with less color banding than the Escape Time algorithm.

<br />

Example:

mandelbrot = Mandelbrot.new<br /> mandelbrot.algorithm = Algorithms::NormalizedIterationCount

Constant Summary collapse

EscapeTime =

:stopdoc:

lambda do |fractal|
  (765 * fractal.last_iteration / fractal.max_iterations).abs
end
NormalizedIterationCount =
lambda do |fractal|
  z = fractal.args[:z]**2 + fractal.c; fractal.last_iteration += 1
  z = z**2 + fractal.c; fractal.last_iteration += 1

  modulus = sqrt(fractal.args[:z].real**2 + fractal.args[:z].image**2).abs
  mu = fractal.last_iteration +
    log(2 * log(fractal.bailout)) - log(log(modulus)) / log(fractal.args[:p])

  (mu / fractal.max_iterations * 765).to_i
end