Home - Blog - 2019-10-05

I made the Mandelbrot fractal in Blender
using nothing but the node system. [1]
If you like, download and play with it. [2]

Click on any picture to see a full-sized version.

colored mandelbrot fractal

The fractal exists in the complex plane. [3]

region of the complex plane

A 2D image, with Red and Green values
for Real and Imaginary numbers, suffices.

node setup for coordinate texture

coordinate texture

This equation is applied to each point:

Zn+1 = Zn2 + C
where C is the point, and Z0 = C.

With real X and Y values,
the equivalent equations are:

Xn+1 = Xn2 - Yn2 + X0
Yn+1 = 2 * Xn * Yn + Y0

nodes to calculate an iteration

If a C's Zn is farther than 2 from 0+0i,
then its later Zs are all far from 0+0i,
and that C is not a part of the fractal.

nodes to calculate distance from 0+0i

Cs that remain have blue added.

nodes to add blue to far pixels

Here are all of the nodes
to calculate one iteration:

all nodes described so far

Nodes are grouped together
for organization and density.

nodes being grouped into x(n), y(n), and outside

In the end, each shade of blue
is turned into a different color, [4]
and the center is turned to black.

nodes to turn shades of blue into rainbow colors

The images is sharpened
by calculating repeatedly.

animation of nodes being added, and the image sharpening

This gives a pretty result.

picture of the mandelbrot set

With more iterations,
the color bands get
harder to tell apart.

Multiplying the normalized steps
and moduloing them back to 0 to 1
makes the colors easier to distinguish.

normalized steps are multiplied by 2 and moduloed by 1

double-rainbow colorized mandelbrot fractal

After figuring this much out,
I found out regerogarc did, too.

I am working on better versions
and neat tricks for this project.
I will post updates when they're done.


[1] Blender can be programmed with Python.
Using that would have made this too easy.
Instead, I used (perhaps abused) Blender's
node-based texture and image compositor systems.

These are meant to be used
to modify the surface of 3D objects
or to filter the final rendered images.

Instead, I'm using them to draw mathy
pictures from scratch, with no 3D models.

Because this is an unusual way to use Blender,
this project is slow and uses a lot of memory.
However, I thought it was a hack worth sharing.

[2] I made this file with Blender 2.79b.
It should work in the latest version, too.

[3] The math for the Mandelbrot fractal
uses numbers called "complex numbers".
If you want to learn complex arithmetic,
you can learn about it on Khan Academy.

[4] The "normalize" node always works, but annoyingly
makes the progress bar show 0% until the frame is done.
Replacing it with a "divide" by the number of iterations
restores the progress bar, but needs to be edited whenever
the number of iterations is changed. (Or add a script.)