## Multibrot Set

The Mandelbrot Set is typically defined as the set of all numbers $c \in \mathbb{C}$ for which — with $z_0 = 0$, $z_{n+1} = f_c(z_n)$ and $f_c(z) = z^2 + c$ — the limit $\lim\limits_{n \to \infty} z_n$ converges. Visualizations of this standard Mandelbrot Set can be seen in three of my posts (Mandelbrot Set, Mandelbrot Set Miscalculations and Mandelbrot Set II).

However, one can extend the fractal’s definition beyond only having the exponent $2$ in the function to be $f_c(z)=z^\text{exp}+c$ with $\text{exp} \in \mathbb{R}$. The third post I mentioned actually has some generalization as it allows for $\text{exp} \in \{2,3,4,5\}$, although the approach used cannot be extended to real or even rational numbers.

The method I used in the aforementioned post consists of manually expanding $(a+b\cdot i)^n$ for each $n$. The polynomial $(a+b\cdot i)^3$, for example, would be expanded to $(a^3 - 3 \cdot a \cdot b^2) + (3 \cdot a^2 \cdot b - b^3) \cdot i$.
This method is not only tedious, error-prone and has to be done for every exponent (of which there are many), it also only works for whole-number exponents. To visualize real Multibrots, I had to come up with an algorithm for complex number exponentiation.

Luckily enough, there are two main ways to represent a complex number, Cartesian form $z = a+b\cdot i$ and polar form $z = k\cdot e^{\alpha\cdot i}$. Converting from Cartesian to polar form is simply done by finding the number’s vector’s magnitude $k = \sqrt{a^2+b^2}$ and its angle to the x-axis $\alpha = \mbox{atan2}(\frac{a}{b})$. (The function $\mbox{atan2}$ is used in favor of $\arctan$ to avoid having to divide by zero. View this Wikipedia article for more on the function and its definition.)
Once having converted the number to polar form, exponentiation becomes easy as $z^\text{exp} = (k \cdot e^{\alpha\cdot i})^\text{exp} = k^\text{exp} \cdot e^{\alpha \cdot \text{exp} \cdot i}$. With the exponentiated $z^\text{exp}$ in polar form, it can be converted back in Cartesian form with $z^\text{exp} = k^\text{exp} \cdot (\cos{(\alpha \cdot \text{exp})} + \sin{(\alpha \cdot \text{exp})} \cdot i \big)$.

Using this method, converting the complex number to perform exponentiation, I wrote a Java program which visualizes the Multibrot for a given range of exponents and a number of frames.
Additionally, I added a new strategy for coloring the Multibrot Set, which consists of choosing a few anchor colors and then linearly interpolating the red, green and blue values. The resulting images have a reproducible (in contrast to randomly choosing colors) and more interesting (in contrast to only varying brightness) look.

The family of Multibrot Sets can also be visualized as an animation, showing the fractal with an increasing exponent. The animated gif shown below was created using ImageMagick’s convert -delay <ms> *.png multibrot.gif command to stitch together the various .png files the Java application creates. To speed up the rendering, a separate thread is created for each frame, often resulting in 100% CPU-usage. (Be aware of this should you render your own Multibrot Sets!)

To use the program on your own, either copy the source code listed below or download the .java file. The sections to change parameters or the color palette are clearly highlighted using block comments (simply search for ‘/*’).
To compile and execute the Java application, run (on Linux or MacOS) the command javac multibrot.java; java -Xmx4096m multibrot in the source code’s directory (-Xmx4096m tag optional, though for many frames at high quality it may be necessary as it allows Java to use more memory).
If you are a sole Windows user, I recommend installing the Windows 10 Bash Shell.

// Java 1.8 Code
// Jonathan Frech, 11th of September 2016
//          edited 17th of April     2017
//          edited 18th of April     2017
//          edited 20th of April     2017
//          edited 21st of April     2017
//          edited 22nd of April     2017

## 4096

4096 is a Java-based clone of the well-known web and mobile game 2048, which itself clones 1024 and is similiar to THREES. The naming trend is quite obvious, though note that $2^{12}$ is a power of two where the exponent is divisible by three, futher connecting to the aforementioned game.

In the game, you are faced with a 4×4 matrix, containing powers of two. By swiping in the four cardinal directions (e.g. pressing the arrow keys), you shove all the non-empty cells to that side. When two equal powers of two collide, they fuse together, adding. Once you shoved, an empty tile pseudo-randomly transforms to either a two-tile (90%) or a four-tile (10%).
Your objective at first is to reach the tile 4096, though the real goal is to achieve the highest score. Your score is the sum of all the collisions you managed to cause.

To play 4096, you can either download the .jar file or review and compile the game for yourself, using the source code listed below.

#### Controls

• Up, down, left or right arrow key shoves the tiles
• Escape restarts the game upon a loss
• F11 toggles fullscreen

// Java 1.8 Code
// Jonathan Frech,  5th of December 2016
//          edited  6th of December 2016
//          edited  7th of December 2016
//          edited  8th of December 2016
//          edited  9th of December 2016
//          edited 19th of February 2017
//          edited 24th of February 2017
//          edited 28th of February 2017
//          * gave the 4096 tile a color
//          edited 22nd of April    2017
//          * fixed window positioning by changing
//            frame.setLocationRelativeTo(null); to
//            frame.setLocationByPlatform(true);

## Mandelbrot Set II

Over a year ago, I published my first Mandelbrot Set viewer, a Python program using pygame. Since then, I have published a rather short program highlighting errors that can occur when calculating the set (Mandelbrot Set Miscalculations).
Since my first viewer was in Python, which is an interpreted programming language, and I wanted to make my viewer faster, I decided to write one in Java. I was hoping for a speed increase since Java is compiled and thus should run at higher speeds. I was not disappointed. The new Java-based viewer runs noticeably faster and additionally I added a lot of new features, all listed below.

#### Controls

• Left-clicking and dragging draws a zoom frame, single left-clicking removes the frame
• Right clicking (and optionally dragging) moves the zoom frame
• Space zooms into the zoom frame
• F1 moves one step back the zoom history
• F2 shows the path a complex number at the cursor’s position follows when the function is iteratively applied
• F3 shows the $\mathbb{R}$ and $\mathbb{R}i$ axis
• F4 displays the current cursor’s corresponding complex number
• F5 toggles between showing and hiding the menu (text in the left upper corner describing the viewer’s functions and current states)
• F6 increments the exponent (going from $f_c(z)=z^2+c$ to $f_c(z)=z^5+c$ in whole-number steps)
• F7 toggles between the Mandelbrot set and the filled Julia set
• F8 toggles between previewing a small filled Julia set at the cursor’s position based upon the cursor’s complex number
• F9 completely resets the zoom and zoom history
• F11 (or F) toggles between fullscreen and windowed mode
• F12 quits the application
• L increases the color depth (starting at $256$ and increasing in steps of $256$)
• Q saves the current image to disk

To use this application, you can either trust me and download the .jar-file or view the source code listed below, verify it and compile the program yourself.
The program will start in fullscreen mode, to change to windowed mode, just press F11 (as listed above).

// Java Code
// Jonathan Frech 14th of September, 2016
//         edited 15th of September, 2016
//         edited 16th of September, 2016
//         edited 17th of September, 2016
//         edited 18th of September, 2016
//         edited 19th of September, 2016
//         edited 23rd of September, 2016
//         edited 24th of September, 2016
//         edited 26th of September, 2016
//         edited 27th of September, 2016
//         edited 28th of September, 2016
//         edited 29th of September, 2016
//         edited 30th of September, 2016
//         edited  1st of October  , 2016
//         edited  2nd of October  , 2016
//         edited  3rd of October  , 2016
//         edited  4th of October  , 2016
//         edited 21st of November , 2016
//         edited 23rd of November , 2016
//         edited 14th of December , 2016
//         edited 13th of January  , 2017
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 29, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6575115919113159, "perplexity": 3347.6727839086934}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-43/segments/1539583512161.28/warc/CC-MAIN-20181018235424-20181019020924-00555.warc.gz"}