# Mandelbrot Set Demo

### Introduction

This application demonstrates advantages of parallel execution done using Java Parallel API.

### About

This JavaFX application renders an image using Mandelbrot set (wikipedia link) for any particular range of complex values.

Given a complex number the algorithm calculates an integer value which is then mapped to a color. Real part of a complex value is mapped to horizontal axis of the screen. Imaginary part of a complex value is mapped to a vertical axis of the screen.

### Navigation

- Drag the picture with left mouse button to explore fractal boundaries.
- Scroll the mouse wheel to zoom in and out.
- Press "1", "2" and "3" control panel buttons to navigate to a particular predefined areas of the fractal.
- Press "0" to return to fractal overview.
- Click "Compare" control panel button to run rendering in comparison mode.
  - In this case the application will re-render the whole picture using:
    1. Sequential execution
    2. Parallel execution
  - Supporting it with visual feedback and showing elapsed time both graphically and in written.
- Type "I" to print current position parameters to the output stream.
- Type "R" to re-render current image using parallel calculation mode.

### Details

`MandelbrotSetTask.call()` method contains code which is equivalent to the following when running in parallel mode:

    IntStream.range(0, height).parallel().forEach((int y) -> {
        for (int x = 0; x < width; x++) {
            // calculate (x, y) pixel color
        }
    });

### Command line options

        java -jar MandelbrotSet.jar -min <minReal>,<minImaginary> -max <maxReal>,<maxImaginary> -windowSize <width>x<height>

- `-min <minReal>,<minImaginary>` specifies left top corner of the fractal complex number area
- `-max <maxReal>,<maxImaginary>` specifies right bottom corner of the fractal complex number area
- `-windowSize <width>x<height>` specifies initial window size in pixels

Here is an example produced by typing "I" inside the app:

    Use the following parameters to get to the same position
    -min -2.4807381162845332,-1.3061943784663503
    -max 0.9781413692299719,1.2879652356695286
    -windowSize 800.0x600.0;

### Source code

- MandelbrotSetTask.java - Mandelbrot Set calculation code
- Complex.java - utility class for Complex numbers operations
- Main.java - JavaFX UI source code
- ControlPane.css - JavaFX CSS file for control panel elements