0

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: enter image description here

How can i get image with better mapping like below image? enter image description here

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
dhavalnc1
  • 129
  • 2
  • 11
  • try using `t / ITERS` or `255 / ITERS` instead of `t` which depends on the RGB intensity range your pixels are using (not a JAVA coder). You can also remap `t` to color by any gradient mapping this is my favorite: [RGB of visible spectra](https://stackoverflow.com/a/22681410/2521214) just linearly interpolate `t` to match the wavelength range ... Also you can crosscheck winth mine [Mandelbrot set I did some years back](https://stackoverflow.com/a/44945883/2521214) – Spektre Apr 09 '18 at 07:23
  • heh a typo the second therm should be `255*t / ITERS` of coarse (too late to edit) – Spektre Apr 10 '18 at 07:10

2 Answers2

0

I would make a histogram to see which color values (in which ranges of values) occur how often in your generated image. Based on this information you can decide in the color-map to use.

At first glimpse it looks like you only get black and withe. The histogram will show if this is the case.

If you find out that
julia(Complex c, Complex z, int maximumIterations)

always return 0 or ITERS-1 , you need to increase ITERS to get more different values.


P.s.
You can also find lots of color-mapping approaches in the www.
e.g. here is an implementation using modulo to cycle through the colors multible times.

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
0

First change your parameter. Now for your image it is c= -0.8+0.1*i which is inside period 2 component of Mandelbrto set ( = connected Julia set). On the second image it is disconnected Juli set ( outside Mandelbrot set) smth like : c = -0.800043099666580 +0.164138006668392 i

Second: it is probably the orbit trap algorithm:

HTH

Adam
  • 1,254
  • 12
  • 25