Skip to content

BenjaminPoole/Fast-Mandelbrot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fast-Mandelbrot

Mandelbrot demo An iteractive GPU-accelerated and cross platform Mandelbrot set explorer built in python.

Usage

It is recommeded to run this program with a GPU as rendering is very much faster.

  1. Clone the repository and run Mandelbrot_Explorer_v1.3.2.py.
  2. Click and drag to move around. Scroll with mouse to zoom.
  3. Use left and right arrow keys to change resolution. Lower res = faster renders.
  4. Use upand down arrow keys to change escape threshold. When you zoom in you will probably need to increase this value because you are computing more iterations.
  5. Press c to toggle false color which by default is grayscale (saves will always be grayscale even with false color).
  6. 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.
  7. 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.

How it works

  1. At the start the program creates a matrix C of all the coordinates in the image it wants to render and a matrix of zeros Z with the same shape as C. 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.
  2. 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 of Z 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.
  3. When the user pans the image or zooms in the program recalculates the matrix C, zeros Z and the process repeats.

Dependancies

  • 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.

Credits

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.

About

A GPU accelerated Mandelbrot set explorer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages