Mandelbrot set

To see the points comprising the Mandelbrot set M all at once, we compute M using the standard ‘escape time’ algorithm. For the complex number c corresponding to each pixel, compute the orbit of z_0=0 under z_{n+1}=z_n^2+c up to some maximum number of iterations (levels slider). If the orbit is bounded, c belongs to M and gets colored red (under the rainbow colorModel). Alternatively, if the orbit is unbounded, compute the smallest value n for which |z_n|>2 and use n, called c‘s escape time, to determine pixel c‘s color.

The Mandelbrot set

Since the maximum number of iterations levels is finite, the red region is a superset of the true Mandelbrot set M. If c\in M, then c gets painted red; however, if c\notin M takes more than levels many iterations to escape, c also gets painted red. As levels increases, the red region contracts toward the true Mandelbrot set, and the greater range of calculated escape times yields finer detail among the points of \overline M.

The ‘binary’ color model maps two colors based on parity of the escape time, where the second color maps to the points belonging to the Mandelbrot set. The ‘gradient’ color model produces a gradient from the first color to the second color, the color of M.

For efficiency, our program defines its own fragment shader for computing pixel colors. This exploits the parallelism and speed of your computer’s graphical processing unit (GPU). It also means that orbits get computed only for the visible pixels (fragments). Remarkably, the shader gets invoked—M is recalculated—for each and every rendering frame.