Help with displaying a Mandelbrot set in Java

I wrote an implementation of a Mandelbrot set in Java using JComponent, but I am getting strange results when rendering it. Also, everything is ready. I'm just not sure what I'm doing with it. Any code review would also be appreciated.

My source has been posted to pastebin as it will take up too much space:

JMandelbrot.java Mandelbrat.java

+2


a source to share


3 answers


Problem:

  • The image is as I expect from the code. The Mandelbrot set has a diameter of 2, so you only see a few pixels in the middle.

Decision:



  • Modify the method renderPoint

    to accept arguments double

    and name it like renderPoint((x - h)/100.0, (k - y)/100.0)

    to see something more interesting.
  • Change the number of iterations and color coding because now you are calculating 255 ^ 3 iterations for each inner pixel. I was able to see something nice by changing the return renderPoint

    to return (((r << 16) | (g << 8) | b)<<4)

    and setting MaxColorBit = 16

    .

Code review:

  • (int)Math.floor(Width / 2)

    can be replaced with Width / 2

    , because it is integer division.
  • You should start your attributes Width

    and Height

    with small letters ( Width

    and Height

    ) because it is the Java agreement, which helps to distinguish the classes and attributes.
  • The attribute is iterations

    not used.
+4


a source


  • You are drawing the fractal correctly, but it is really small. The entire Mandelbrot set fits into a circle of radius 2, so it barely covers a few pixels in the middle of the 400x500 window.

    You have to design some kind of mapping from the screen window (from (0,0)

    to (width,height)

    ) to the complex plane, which should have values ​​in the vicinity of -2-2i

    to 2+2i

    or so on. A quick fix would be to split the expressions x-h

    and k-y

    by 100

    before passing them to renderPoint

    , and change the arguments renderPoint

    from int

    to double

    . Your best bet would be to specify the desired view rectangle and use that to define the display.

  • You compute a fractal image on the GUI thread. This is no-no, as the application seems to hang before the window is finished. I would change the call render()

    in the constructor to look like this:

    new Thread() {
      public void run() { render(); }
    }.start();
    
          



+2


a source


Take a look at this example of Mandelbrot fractal rendering by Marvin: http://marvinproject.sourceforge.net/en/plugins/mandelbrot.html

There is also a Julia rendering plugin: http://marvinproject.sourceforge.net/en/plugins/juliaSet.html

0


a source







All Articles