I am working on julia set in java. Following is my code:
public class ColorJulia {
// return number of iterations to check z is in the Julia set of c
static int julia(Complex c, Complex z, int maximumIterations) {
for (int t = 0; t < maximumIterations; t++) {
if (z.abs() > 2.0) return t;
z = z.times(z).plus(c);
}
return maximumIterations - 1;
}
public static void main(String[] args) {
double real = -0.8;//Double.parseDouble(args[0]); // a
double imag = 0.1;//Double.parseDouble(args[1]); // b
Complex c = new Complex(real, imag); // c = a + ib
double xmin = -2.0;
double ymin = -2.0;
double width = 4.0;
double height = 4.0;
int n = 512;
int ITERS = 256;
int freq[]=new int[256];
Arrays.fill(freq, 0);
Picture picture = new Picture(n, n);
// read in color map
Color[] colors = new Color[ITERS];
for (int t = 0; t < ITERS; t++)
{
int r = t;
int g = t;
int b = t;
colors[t] = new Color(r, g, b);
}
for (int col = 0; col < n; col++)
{
for (int row = 0; row < n; row++)
{
double x = xmin + col * width / n;
double y = ymin + row * height / n;
Complex z = new Complex(x, y);
int t = julia(c, z, ITERS);
freq[t]++;
Color testPixel = new Color(t,t,t);
picture.set(col, row, testPixel);
}
}
picture.show();
for(int i=0;i<256;i++)
{
System.out.println("freq " + i + " = " + freq[i]);
}
}
}
Now, I am getting output image as follow:
How can i get image with better mapping like below image?
In julia set, i am generating RGB color using return value of iteration. I don't know how to map this colors to get better image.