User:Simpsons contributor/Julia set creator. Self made

package newtonsmethodfractal;

import java.awt.image.BufferedImage;

/*Uses Newton's method on a plane of complex numbers, * represented by a 2-d array of Complex objects, to * produce a fractal. The fractal represents how long * it takes for each point to converge on the root * (attractor) and which root (attractor) it ends at. */ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO;

public class JuliaSet {   BufferedImage image; private int TYPE = BufferedImage.TYPE_INT_RGB; private double xLength, yLength; private double xDifference, yDifference; private double xLocation, yLocation; private int counter, rgb, red, green, blue; private Complex valueN = new Complex; private Complex valueNPlus1 = new Complex; private ComplexOperations operations = new ComplexOperations; private double real, imaginary, z, colour; public JuliaSet(int width, int height, double xMin, double xMax,                    double yMin, double yMax, int maxIteration, int multiple,                    Complex inputComplex,  String name) throws IOException {                 /*Create a new complex plane and BufferedImage * based upon the width and height dimensions*/ image = new BufferedImage(width, height, TYPE); /*The complex number plane has the dimensions of the image * [width] [height]. The values of the complex numbers in        * the complex number plane is different. Use the values of        * xMin, xMax, yMin and yMax to fill the plane with the * actual values of the plane. */       //Work out the length width of the complex plane xLength = xMax - xMin; yLength = yMax - yMin; /*Work out the difference on the x and y axes that results from * the move from one pixel to the next */ xDifference = xLength / width; yDifference = yLength / height; /*Set xLocation and Ylocation to xMin and yMin and then sweep * through the complex plane in an x-y fashion setting each real * and imaginary value on the way */ xLocation = xMin; yLocation = yMin; for(int x=0; x<width; x++) {           for(int y=0; y<height; y++) {                                         counter = 0; //Create new complex and set it to coordinates valueN.setReal(xLocation); valueN.setImaginary(yLocation); valueNPlus1.setReal(xLocation); valueNPlus1.setImaginary(yLocation); //Get values real = valueN.realDouble; imaginary = valueN.imaginaryDouble; while(real*real + imaginary*imaginary <= 4 &&                      counter < maxIteration) {                    //Create (n+1) complex: x(n+1) = x(n)^2 + c                     valueNPlus1 = operations.multiply(valueNPlus1, valueNPlus1); valueNPlus1 = operations.add(valueNPlus1, inputComplex); //Get values real = valueNPlus1.realDouble; imaginary = valueNPlus1.imaginaryDouble; //Advance counter by one counter++; }                                 //Select a colour based on the iteration number and the hue line /*more than	less than or equal to	red	green	blue 0	       255	                255	0-255	0                255	        510	                255-0	255	0                510	        765	                0	255	0-255                765	        1020	                0	255-0	255                1020	        1275	                0-255	0	255                1275	        1530	                255	0	255-0*/                //Increase = iteration - lower bound //Decrease = upper bound - iteration if(counter == maxIteration) {                   red = 0; green = 0; blue = 0; //Black }               else //Non-black {                   /*   Normalized iteration count algorithm: _________                   |z| = \/x^2 + y^2

ln(ln(|z|)) n + 1 - --- ln 2               */ z = Math.sqrt(real*real + imaginary*imaginary); colour = counter + 1 - (Math.log(Math.log(z)) / Math.log(2)); //Convert "iteration" to new "colour" value Number colourNumber = multiple * colour; counter = colourNumber.intValue; if(counter <= 255) {                       red = 255; blue = 0; green = counter; }                   if(counter > 255 && counter <= 510) {                       green = 255; blue = 0; red = 510 - counter; }                   if(counter > 510 && counter <= 765) {                       green = 255; red = 0; blue = counter - 510; }                    if(counter > 765 && counter <= 1020) {                       blue = 255; red = 0; green = 1020 - counter; }                   if(counter > 1020 && counter <= 1275) {                       blue = 255; green = 0; red = counter - 1020; }                   if(counter > 1275) {                       red = 255; blue = 255; green = 0; }                } //End of non-black colour determine rgb = ((1 & 0xFF) <<24) | ((red & 0xFF) <<16) | ((green & 0xFF) <<8) | ((blue & 0xFF) <<0); image.setRGB(x, height-y-1, rgb); yLocation = yLocation + yDifference; }           yLocation = yMin; xLocation = xLocation + xDifference; } //End of nested for loops File createFolder = new File("C:/Fractal/"); createFolder.mkdir; //Save the image File saveFile = new File("C:/Fractal/" + name + ".png"); try { ImageIO.write(image, "png", saveFile); } catch (IOException ex) { Logger.getLogger(MethodProcess.class.getName).log(Level.SEVERE, null, ex); }   } }