Class: Fractals::Fractal

Inherits:
Renderers::Base show all
Defined in:
lib/fractals.rb

Overview

The Fractal base class.

Direct Known Subclasses

BurningShip, Julia, Mandelbrot, Newton

Instance Attribute Summary collapse

Attributes inherited from Renderers::Base

#algorithm, #bailout, #height, #last_iteration, #magnification, #max_iterations, #set_color, #theme, #width

Instance Method Summary collapse

Methods inherited from Renderers::Base

acts_as_renderer, #in_set?, #render, #renderer=, #where_is?

Constructor Details

#initialize(c, args, &expression) ⇒ Fractal

Sets the default property values.



46
47
48
49
# File 'lib/fractals.rb', line 46

def initialize(c, args, &expression)
  @c, @args, @expression = c, args, expression
  super()
end

Instance Attribute Details

#argsObject

A Hash of arguments used in the fractal’s expression.



39
40
41
# File 'lib/fractals.rb', line 39

def args
  @args
end

#cObject

The complex number seed.



37
38
39
# File 'lib/fractals.rb', line 37

def c
  @c
end

#expressionObject

The fractal’s expression as a block.



41
42
43
# File 'lib/fractals.rb', line 41

def expression
  @expression
end

Instance Method Details

#iterate(n) ⇒ Object

Iterates the fractal’s expression n times yielding the iteration number and result.



53
54
55
56
57
58
59
# File 'lib/fractals.rb', line 53

def iterate(n)
  @args[:z] = @args[:c]
  n.times do |i|
    @expression.call(@args)
    yield i, @args[:z]
  end
end