Class Buddhabrot

java.lang.Object
  extended by Fractal
      extended by Buddhabrot

public class Buddhabrot
extends Fractal

This class supports the 2011-2012 ICS3U Final Exam. As an alternative fractal algorithm to the Mandelbrot class, this class similarly extends Fractal. No palette object is required as the grayscale colors are determined from the recorded data itself.

Author:
Chris Darcy

Field Summary
 
Fields inherited from class Fractal
bailout, bottomBound, centreX, centreY, delta, dimension, domain, filename, invert, iteration, iterations, leftBound, MAX_ITERATE, palette, paletteName, point, range, rightBound, TARGET, topBound, xCenter, xMax, xMin, yCenter, yMax, yMin
 
Constructor Summary
Buddhabrot(java.lang.String xC, java.lang.String yC, java.lang.String delta, java.lang.String bailout, java.lang.String samples, java.lang.String filename)
          The Buddhabrot constructor accepts parameters similar to the Mandelbrot class constructor.
 
Method Summary
protected  void draw(java.awt.Graphics g)
          This method overrides Fractal's draw method to render the Buddhabrot image.
protected  void findMaxHitCount()
          This method is called by iterateSamples after the iterate method has entirely populated the 2D hitCounts array.
protected  boolean iterate(ComplexNumber c, boolean recordIt)
          Called by iterateSamples for each c.
protected  void iterateSamples()
          This method runs through a loop from 0 to samples.
 
Methods inherited from class Fractal
getDimension, getFilename, getMaxIterations, isPartOfSet, iteration, mapColumnToReal, mapImaginaryToRow, mapRealToColumn, mapRowToImaginary, setDimension, setEscapeTime, zoom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Buddhabrot

public Buddhabrot(java.lang.String xC,
                  java.lang.String yC,
                  java.lang.String delta,
                  java.lang.String bailout,
                  java.lang.String samples,
                  java.lang.String filename)
The Buddhabrot constructor accepts parameters similar to the Mandelbrot class constructor. Since a palette object is not required, simply pass null to the Fractal constructor in its place. The number of c values to randomly generate (samples) can be saved and used locally as it is not required by the Fractal superclass.

Parameters:
xC - the real value of the center
yC - the imaginary value of the center
delta - the half width of the region of the Argand Plane centered at xC+yCi
bailout - the maximum allowed exposure before concluding the c value did not escape
samples - the number of random c values to test
filename - the name of the file for the purpose of saving the image
Method Detail

draw

protected void draw(java.awt.Graphics g)
This method overrides Fractal's draw method to render the Buddhabrot image. The method first calls the iterateSamples method to populate the 2D array hitCounts for those c that escaped the Mandelbrot Set. After which the maximum hit count is determined and used as a denominator for all entries in hitCount to achieve a float value between 0.0f and 1.0f. This value is used an the red, green, and blue values in the Color(float,float,float) constructor and the pixel is drawn.

Overrides:
draw in class Fractal
Parameters:
g - the Graphic2D reference to the bufferedImage passed to it by Plot's getImage method

iterateSamples

protected void iterateSamples()
This method runs through a loop from 0 to samples. With each iteration a random c value within the region of the Argand Plane is constructed and passed to the iterate method to determine if it escaped the Set, given the bailout limit. Only if it did escape does the same c value get passed to the iterate method a second time, this time each z in its orbit is recorded in the 2D hitCounts array (provided the corresponding row and column are within the bounds of the array).


iterate

protected boolean iterate(ComplexNumber c,
                          boolean recordIt)
Called by iterateSamples for each c. Each c is given a a maximum number of iterations (bailout) to determine if the orbit escaped the Mandelbrot Set (|z|>2.0) if it escapes the method returns a value true; false otherwise. If the drawIt parameter is true, the 2D hitCounts array is incremented for each z in the orbit. This requires that the Fractal methods
        protected int mapRealToColumn(double x)
        protected int mapImaginaryToRow(double y)
 
be called to determine the pixel location corresponding to z.

Parameters:
c - the ComplexNumber to sampled
recordIt - whether or not hits are to be record in the hitCounts array

findMaxHitCount

protected void findMaxHitCount()
This method is called by iterateSamples after the iterate method has entirely populated the 2D hitCounts array. This method traverses the entire hitCounts array to determine the maximum hit count, setting the instance field maxHitCount to this value.