Note: This post requires you to have a basic understanding of complex numbers. If you don’t know what complex numbers are, you can read about them here.
Introduction
I love coding, and I also have a passion for mathematics. I’ve always wanted to combine my love of coding and my knowledge of mathematics to create interesting but also educational visualization, something is similar to the works of 3Blue1Brown and The Coding Train.
I’ve always been fascinated by fractals. They are geometric entities with infinite amount of roughness. They have fractional dimensions (not 1D, 2D, or 3D). Among them, Mandelbrot set is one of the well-known fractals. Since the generation process is simple and straightforward, it is a great entry point for people who want to code their own fractal visualizations. However, there are some challenges when rendering fractals in real time.
What is Mandelbrot set?
The Mandelbrot set is a fascinating fractal discovered by Benoit Mandelbrot in 1980. To generate the set, we need series of complex numbers starting from and recursively apply the function , where is a complex constant.
In general, we have a series of complex numbers
This series will eventually converge to a point, oscillate, or diverge to infinity and depends on the choice of constant . If the series diverges to infinity, then the point is not in the Mandelbrot set. On the other cases, is in the set.
What I use to render Mandelbrot set?
- For the frontend UI, I use Svelte as my preferred framework.
- For the visualization tool, I use p5.js, a powerful tool for creative coding. Also, it abstracts away the WebGL pipeline.
- I use GLSL to write the shader code for the fractals.
Bonus: The Julia Set
The Julia set is a fractal is the fractal that use the same recursive function as the Mandelbrot set. However, the iterative process to generate Julia is quite different from the Julia set. Instead of starting with initial and plotting the constant , we would start with arbitrary and plot the initial value . This leads to different choice of constant resulting in different Julia set.