An iteractive GPU-accelerated and cross platform Mandelbrot set explorer built in python.
It is recommeded to run this program with a GPU as rendering is very much faster.
- Clone the repository and run
Mandelbrot_Explorer_v1.3.2.py
. - Click and drag to move around. Scroll with mouse to zoom.
- Use left and right arrow keys to change resolution. Lower res = faster renders.
- Use
up
anddown
arrow keys to change escape threshold. When you zoom in you will probably need to increase this value because you are computing more iterations. - Press
c
to toggle false color which by default is grayscale (saves will always be grayscale even with false color). - Press
s
to save image of render on screen. This will save the image as a png to either your home directory or current working directory depending on your OS. - Julia set only: Use
k
j
l
h
to move the Julia-set seed coordinate up, down, left, and right resp.
The image filename will contain the coordinates of where you are in the Mandelbrot set etc to enable reproducible results. The top bar of the program also shows coordinates of where you are as well as the resolution and escape brightness.
- At the start the program creates a matrix
C
of all the coordinates in the image it wants to render and a matrix of zerosZ
with the same shape asC
. By using a matrix of complex numbers instead of iterating scalar values this allows the computation to be parallelized and thus enables GPU computation for maximum render speed. - The iterative formula
Z = Z^2 + C
is then applied every iteration. To render the set the program measures how many iterations it takes for a given value ofZ
to diverge (magnitude > 4) and that pixel is assigned a corresponding brightness where the upper limit of the brightness is set by the escape threshold. Next the gradient of its value w.r.t the last iteration is computed and that pixel is assigned a brightness corresponding to the magnitude of the gradient. - When the user pans the image or zooms in the program recalculates the matrix
C
, zerosZ
and the process repeats.
- Python 3 with pytorch, pygame, matplotlib and numpy installed. Make sure to install the GPU version of pytorch if you have a GPU. This program has been tested on both Windows 10 and Linux.
This program was based on this notebook and the corresponding Youtube video which taught the author how to do this.
Thanks to Stephen Fay for contributing Julia.py so you can render Julia sets.
If you wish to ask questions/report a bug or contribute then make sure to open an issue and let me know.