Fast mandelbrot set renderer using goroutines
fractals is a customizable renderer for the Mandelbrot set written in Go. It uses Go's goroutines to achieve high performance.
git clone https://github.com/joweich/fractals.git
cd fractals
go build
./fractals -h # to see list of available customizations
./fractals -height 1000 -width 1000 # fractals.exe for Windows systems
The Mandelbrot set is defined as the set of complex numbers $c$ for which the series
$$z_{n+1} = z²_n + c$$
is bounded for all $n ≥ 0$. In other words, $c$ is part of the Mandelbrot set if $z_n$ does not approach infinity. This is equivalent to the magnitude $|z_n| ≤ 2$ for all $n ≥ 0$.
The image is interpreted as complex plane, i.e. the horizontal axis being the real part and the vertical axis representing the complex part of $c$.
The colors are determined by the so-called naïve escape time algorithm. It's as simple as that: A pixel is painted in a predefined color (often black) if it's in the set and will have another color if it's not. The color is determined by the number of iterations $n$ needed for $z_n$ to exceed $|z_n| = 2$. This $n$ is the escape time, and $|z_n| ≥ 2$ is the escape condition. In our implementation, this is done via the hue parameter in the HSL color model for non-grayscale images, and the lightness parameter for grayscale images.
Each row of the image is added as a job to a channel. These jobs are distributed using goroutines (lightweight threads managed by the Go runtime) that are spun off by consuming from the channel until it's empty.