Class: Fractals::Newton

Inherits:
Fractal show all
Defined in:
lib/fractals.rb

Overview

The Newton fractal.

Instance Attribute Summary

Attributes inherited from Fractal

#args, #c, #expression

Attributes inherited from Renderers::Base

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

Instance Method Summary collapse

Methods inherited from Fractal

#iterate

Methods inherited from Renderers::Base

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

Constructor Details

#initialize(c = Complex(0.0, 0.0)) ⇒ Newton

Returns a new instance of Newton.



92
93
94
95
96
97
98
# File 'lib/fractals.rb', line 92

def initialize(c=Complex(0.0, 0.0))
  super(c, {:a => 1, :pz => lambda { |z| z**3 - 1 }}) do |args|
                                                        dx_pz = derivative(0.0001) { |x| args[:pz].call(x) }
                                                        args[:z] = args[:z] - args[:a] *
                                                          (args[:pz].call(args[:z]) / (dx_pz.call(args[:z])))
                                                      end
end