/* This class is a generic base (parent) class for Fractal drawing algorithms, as many of the true fractal methods have quite a few properties in common. */ public class Fractal { /* Similar to how we do 2D Graphing in processing, fractals work in a virtual space that we need to translate to our screen space. Where 2D Graphing used an X/Y space (usually from -4 to 4, or -8 to 8), Fractals work with Real and Imaginary numbers. The Real number correspond to the X axis, the Imaginary numbers to the Y axis. */ protected double min_RE; protected double max_RE; protected double min_IM; protected double max_IM; protected double step_RE; protected double step_IM; // how many iterations to use in calculating our fractal protected int maxIterations; // Colors for drawing our fractal public ColorRGB inColor; public ColorRGB edgeColor; public ColorRGB midColor; public ColorRGB outColor; public Fractal() { // set default values for the real and imaginary numbers min_RE = -2.0; max_RE = 1.0; min_IM = -1.2; max_IM = min_IM + (max_RE - min_RE) * (height / width); step_RE = (max_RE - min_RE) / (width - 1); step_IM = (max_IM - min_IM) / (height - 1); maxIterations = 35; outColor = new ColorRGB(32, 64, 128); midColor = new ColorRGB(255, 255, 255); edgeColor = new ColorRGB(186, 186, 186); inColor = new ColorRGB(45, 45, 45); } public void setRealRange(double minR, double maxR) { min_RE = minR; max_RE = maxR; } public void setImaginaryRange(double minI, double maxI) { min_IM = minI; max_IM = maxI; } public double getMinReal() { return min_RE; } public double getMaxReal() { return max_RE; } public double getMinImaginary() { return min_IM; } public double getMaxImaginary() { return max_IM; } public void setMaxIterations(int it) { maxIterations = it; } public int getMaxIterations() { return maxIterations; } public void render() { } public double getRealAtX(int x) { double realRange = max_RE - min_RE; double numRange = (double)x / (double)width; return min_RE + (realRange * numRange); } public double getImaginaryAtY(int y) { double imaginaryRange = max_IM - min_IM; double numRange = (double)y / (double)height; return min_IM + (imaginaryRange * numRange); } }