Julia Set: Animate your own in Python with Matplotlib

1 minute read

An Infinity within infinity. That's how we can describe the bizarre fractal geometry. This geometry is defined by a self-similar symmetry that exhibits the same or similar patterns regardless of the scale at which we zoom over.

We already covered the fascinating properties of the Mandelbrot set and the Koch Curve, which are also fractals. In this post, we make an animated visualization of the Julia Set, which is a special kind of fractal. We implement the numerical simulation using Python augmented with an animated visualization in Matplotlib.

Definition

Similar to the Mandelbrot Set, the Julia Set is a set of all complex numbers \( z \) for a given \( c = x + i*y \), such that the sequence \( z_{n+1} = z_{n}^{2} + c \) is bounded. We can easily visualize all such complex numbers in the complex plane and get a stunning plot. All we have to do is to associate a color (from a predefined palette of colors), corresponding to the number of steps before the sequence diverges. If it diverges, the color is set to black.

Animated Visualization

The number \( c = x + i*y \) gives us the freedom to set it to a range of values and produce mind-blowing animations. We get one particular and very interesting range of values if we represent \( c \) as \( c = r\cos\alpha + i * r \sin\alpha = re^{i * \alpha} \), for \( r = 0.7885 \) and \( \alpha \in [0, 2\pi] \).

Using Matplotlib's Animation API, we visualize the convergence of the Julia Set over this interesting range of values for \( c \). This is depicted in the animation below:

Animated Visualization of the Julia set convergence for different values of the parameter c
Animation: Julia set convergence for \( c = re^{i * \alpha} \) as \( \alpha \) changes counterclockwise

The source code behind this animation and simulation can be found in this Python Notebook.

If this illustration of the Julia Set is interesting to you, feel free to share it on the social media. Also, it would help if you subscribe to the mailing list below. You will get cool animations like this one from time to time. Thanks for reading this article!

Leave a comment