The colors embellish the picture.
But that is not the main reason why different colors are used.
The Mandelbrot set is colored black.
If only two colors are used (black: Mandelbrot, white: not Mandelbrot), then
the border of the Mandelbrot set can hardly be seen due to bad resolution.
When extra colors are used, the Mandelbrot set becomes more visible.
We use the following colors:
black, if after 100 iterations the sequence (x0,y0), (x1,y1), ...
is still present inside the circle with center (0,0) and radius 2.
(Why radius 2? See the explanation below the line.)
gray, if that sequence left the circle between 70% and 100% of the maximal number of iterations,
green, between 50% and 70% of the maximal number of iterations,
yellow between 30% and 50% and orange between 10% and 30%.
When you click on the blue square, then the maximal number of iterations is raised by 2.
When the sequence (x0,y0), (x1,y1), ... leaves the circle with radius 2
it will run away heading infinity.
We will show this here.
Notice that the elements (a,b) of the Mandelbrot set are all situated inside the circle
(a2 + b2) ≤ 2 (see the picture of the Mandelbrot set).
Suppose (xn,yn) is outside the circle with radius 2,
then (xn2 + xn2) > 2 + e, with e>0.
Then we will now show that (xn+12 + yn+12) > (1+e)(xn2 + xn2),
and so (xn+12 + yn+12) > 2 + e, so that (xn+22 + yn+22) > (1+e)2(xn2 + xn2) > (1+2e)(xn2 + xn2) and (with induction)
(xn+k2 + yn+k2) > (1+ke)(xn2 + xn2).
Consequently, the sequence raises to infinity. Proof: