DEV Community

Cover image for Mandelbrot and Julia - Mathematical visualization and beauty
Vidya
Vidya

Posted on

Mandelbrot and Julia - Mathematical visualization and beauty

I have been fascinated by the idea of chaos theory since I read about the butterfly effect. I read some more about it in the book 'Chaos' by James Gleick including about the Mandelbrot. But until I read 'Make your own Mandelbrot' by Tariq Rashid I did not realize just how simple the equation to draw the Mandelbrot was.

This is the innocuous looking equation that generates the awesome Mandelbrot Set.

Alt Text

A slight change in the input to the same equation will give the Julia set. It gives rise to a complicated boundary that reveals a recursive aspect; there are many smaller sized Mandelbrot one can see as one zoom's in.

To learn more - look at this video - "What's so special about the Mandelbrot Set?"

So I used the code from the book (python) to get the Mandelbrot set and the Julia set. I also got to see the 3D surface close ups (after smoothing).

MandelBrot 3D

MandelBrot 3D

Julia 3D

Julia 3D

But the fun of the Mandelbrot is when one can zoom in and see the beautiful patterns interactively.

After a bit of search (and multiple tries), I was able to finalize on JavaScript code works reasonably without needing specific libraries or frameworks or threads. I also improved on the color palette, to get brightly colored areas to observe the beauty of the mathematical patterns.

Following is the core of the Mandelbrot code. This calculates the value of the function for a maximum number of iterations.

MandelBrot Code


Ref : https://rembound.com/articles/drawing-mandelbrot-fractals-with-html5-canvas-and-javascript

Julia Code


Ref : https://rosettacode.org/wiki/Julia_set

Color Palette Code


Ref : https://rosettacode.org/wiki/Julia_set

Results

Using mousedown to zoom in, ctrl to zoom out and shift to pan in the Mandelbrot and Julia results, the images (converted to gifs) is shown below.

Links to the live demo are also mentioned at the end of the post.

Mandelbrot gif

Mandelbrot gif

Julia gif

Julia gif

Links

Live Demo - Mandelbrot

Live Demo - Julia

Full Code Mandelbrot in JS

Full Code Julia in JS

Python notebook with 3D images - Mandelbrot

Python notebook with 3D images - Julia

References

1. Make your own Mandelbrot - Tariq Rashid 

If you don't know programming or mathematics, and want to start from scratch to understand the concept behind Mandelbrot in clear, simple and step-by-step manner, this book is great. Short (only ~130 pages), with plenty of illustrations, easy to grasp. Its only con is that the code is in Python 2.7.

2. HTML5 Canvas and Javascript - Main resource for the javascript code for zoom and pan function. 

3. Color palette - Simplest color palette code for a wide range of colors

4. Various values of C for Julia sets

5. Color Inspiration

Top comments (2)

Collapse
 
epsi profile image
E.R. Nurwijayadi

Inspiring. Thank youuuuu.

Collapse
 
vidyabhandary profile image
Vidya

Thank you so much !