To see the points comprising the Mandelbrot set all at once, we compute using the standard ‘escape time’ algorithm. For the complex number corresponding to each pixel, compute the orbit of under up to some maximum number of iterations (levels slider). If the orbit is bounded, belongs to and gets colored red (under the rainbow colorModel). Alternatively, if the orbit is unbounded, compute the smallest value for which and use , called ‘s escape time, to determine pixel ‘s color.
Since the maximum number of iterations levels is finite, the red region is a superset of the true Mandelbrot set . If , then gets painted red; however, if takes more than levels many iterations to escape, 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 .
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 .
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— is recalculated—for each and every rendering frame.