Mandelbrot Set in Java

Mandelbrot Set in Java with Iceberg Charts

The Mandelbrot Set is one of the most famous images in all of mathematics. It is a set of complex numbers which do not escape when applied to a simple methematical formula. You can read more about it on Wikipedia.

To write this in Java it is basically the algorithm, where each x and y value is checked against the simple formula x^2 + y^2 < c. (where c in our case is 5) .

while (x * x + y * y < 5 && iterations < max) {
double x_new = x * x – y * y + c_re;
y = 2 * x * y + c_im;
x = x_new;

We have a max iteration, where we consider that if the equation still hasn’t been fulfilled at the max iteration then the point will remain bounded. If it stays bounded then we consider it part of the set, and we add it to our chart set :

Out XYDataSeries is just a an XY series of one pixel square, with no line connectors. All we are doing is plotting out all these values once we have finished going through the iteration.


This creates a chart that looks like this :


That looks pretty simple and straight forward. What if we want to do colors as well? If we assign a different color to an iteration that escapes after a particular number of iterations we can get some pretty cool shading. Eg. if our iteration escapes after only 5 iterations we could have a light red, and if it escapes after 999 iterations then we could use a dark red.

The following code creates a number of XY data series based on the number of possible iterations. For each iterations a different color is used.

This produces a colorful and beautiful chart that looks like this :


Pretty cool, huh?

These two examples can be found in the Iceberg Charts Project as and

Download Iceberg Charts Here





Posted in Iceberg Charts | Tagged , | 1 Comment

One Response to Mandelbrot Set in Java

  1. novice says:

    Hi oliver,

    I was wondering if you could do a tutorial on how to install this? I’m having trouble installing it on Eclipse. I first extract the zip file and just go to Java Built Path like I do my usual jar files but when I try selecting add class folder instead nothing happens. How exactly do I install Iceberg charts?


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">