This repository contains a Python implementation for visualizing the Mandelbrot set, adapted from the Rosetta Code reference implementation.
The program computes and displays a graphical representation of the Mandelbrot set using NumPy for numerical computation and Matplotlib for visualization.
The Mandelbrot set is defined through the iterative function:
zₖ₊₁ = zₖⁿ + c
where:
- z and c are complex numbers
- n is a positive integer (default: n = 2)
- z₀ = 0
For each complex number c, the sequence is iterated up to a maximum number of iterations.
A point c belongs to the Mandelbrot set if the sequence remains bounded:
|zₖ| < 2 for all k
If |zₖ| ≥ 2, the sequence is said to escape to infinity.
-
Construct a 2D grid of complex numbers:
- Real axis in [-2, 2]
- Imaginary axis in [-2, 2]
-
Initialize:
- Z = 0
- Track escape (exit) times for each point
-
Iterate:
- Z ← Zⁿ + C
- Record iteration number when |Z| ≥ 2
-
Visualize:
- Escape times are mapped to colors
- Displayed using Matplotlib colormap
- Adjustable resolution (
npts) - Adjustable maximum iteration depth (
max_iter) - Configurable exponent (
n) - Vectorized NumPy implementation
- Color-mapped escape-time visualization
- Python 3.8+
- NumPy
- Matplotlib
Install dependencies with:
pip install numpy matplotlib
Run the script directly:
python mandelbrot.py
Default execution:
mandlebrot(1000, 130, 2)
mandlebrot(npts=300, max_iter=100, n=2)
npts: Controls resolution (higher → more detail)max_iter: Maximum number of iterationsn: Exponent in the iteration formula zⁿ + c
- A graphical window displaying the Mandelbrot set
- Color intensity corresponds to escape time
- Higher iteration depth reveals finer boundary structure
- Single-threaded CPU implementation
- No zoom or interactive exploration
- Memory usage increases with resolution
- No image export functionality (display only)