Package com.barrybecker4.simulation.fractalexplorer.algorithm

Source Code of com.barrybecker4.simulation.fractalexplorer.algorithm.MandelbrotAlgorithm

/** Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT  */
package com.barrybecker4.simulation.fractalexplorer.algorithm;

import com.barrybecker4.common.math.ComplexNumber;
import com.barrybecker4.common.math.ComplexNumberRange;

/**
* Populates the FractalModel using the iterative Mandelbrot algorithm..
*
* @author Barry Becker
*/
public class MandelbrotAlgorithm extends FractalAlgorithm  {

    private static final ComplexNumberRange INITIAL_RANGE =
            new ComplexNumberRange(new ComplexNumber(-2.1, -1.5), new ComplexNumber(1.1, 1.5));

    public MandelbrotAlgorithm(FractalModel model) {
        super(model, INITIAL_RANGE);
        model.setCurrentRow(0);
    }

    @Override
    public double getFractalValue(ComplexNumber initialValue) {

        ComplexNumber z = initialValue;
        int numIterations = 0;

        while (z.getMagnitude() < 2.0 && numIterations <  getMaxIterations()) {
            z = z.power(2).add(initialValue);
            numIterations++;
        }

        return (double) numIterations / getMaxIterations();
    }

}
TOP

Related Classes of com.barrybecker4.simulation.fractalexplorer.algorithm.MandelbrotAlgorithm

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.