import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
and so there is no need for randomize
anymore and the whole program changes as follows
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static int randomize(int left, int right)
{
return left + (int) Math.random()*(right-left);
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*13*(256-i) % 256;
green = randomize(4,10)*7*(256-i) % 256;
blue = randomize(8,14)*11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
and so the whole program changes as follows
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static int randomize(int left, int right)
{
return left + (int) Math.random()*(right-left);
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
and so there is no need for randomize
anymore and the whole program changes as follows
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
After experimenting with my program for two days, I found that the use of degree
within the methods checkDegreeOfDivergence
and createRandomColors
does not increase the quality of the pictures and so I removed it.
Also to increase the variety of colors I changed the following code
public static Color[] createRandomColors(int degree)
{
Color[] colors = new Color[degree+1];
colors[degree] = new Color(0,0,0);
double r = Math.random();
int red = 0, green = 0, blue = 0;
for (int i = 0; i < degree; i++)
{
red = 13*(256-i) % 256;
green = 7*(256-i) % 256;
blue = 11*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
return colors;
}
into
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
and so the whole program changes as follows
import java.awt.Color;
public class MandelbrotSet
{
public static int checkDegreeOfDivergence(Complex c)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = nextRecurrence.times(nextRecurrence).plus(c);
}
return 255;
}
public static int checkDegreeOfDivergenceForMandelblar(Complex c, int degree)
{
Complex nextRecurrence = c;
for (int i = 0; i < 255; i++)
{
if (nextRecurrence.abs() >= 2) return i;
nextRecurrence = (nextRecurrence.conjugate()).times(nextRecurrence.conjugate()).plus(c);
}
return 255;
}
public static int randomize(int left, int right)
{
return left + (int) Math.random()*(right-left);
}
public static Color[] createRandomColors()
{
Color[] colors = new Color[256];
double r = Math.random();
int red = 0, green = 0, blue = 0;
if (r < 1.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,green,blue);
}
}
else if (r < 2.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(red,blue,green);
}
}
else if (r < 3.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,red,blue);
}
}
else if (r < 4.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(green,blue,red);
}
}
else if (r < 5.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,red,green);
}
}
else if (r < 6.0/6.0)
{
for (int i = 0; i < 256; i++)
{
red = randomize(10,16)*(256-i) % 256;
green = randomize(4,10)*(256-i) % 256;
blue = randomize(8,14)*(256-i) % 256;
colors[i] = new Color(blue,green,red);
}
}
return colors;
}
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]);
int height = Integer.parseInt(args[1]);
double x = Double.parseDouble(args[2]);
double y = Double.parseDouble(args[3]);
double zoom = Double.parseDouble(args[4]);
Picture mandelbrotSet = new Picture(width,height);
Color[] colors = createRandomColors();
for (int j = 0; j < width; j++)
{
for (int i = 0; i < height; i++)
{
double realPart = x + zoom*j/width;
double imaginaryPart = y + zoom*i/height;
Complex c = new Complex(realPart,imaginaryPart);
int degreeOfDivergence = checkDegreeOfDivergence(c);
Color color = colors[degreeOfDivergence];
mandelbrotSet.set(j,i,color);
}
}
mandelbrotSet.show();
}
}
lang-java