How can I build a Julia set?

Pick a point on the complex plane (let's call it C). The corresponding complex number has the form: x_coordinate + i*y_coordinate. The following algorithm produces the Julia set associated with C: given a generic point Z on the complex plane, this algorithm determines whether or not it belongs to the Julia set associated with C, and thus determines the color that should be assigned to it.

In order to see if Z belongs to the set, we must iterate the function Zn+1 = Z2n + C using Z0 = Z. What happens to the initial point Z when the formula is iterated? Will it remain near to the origin or will it go away from it, increasing its distance from the origin without limit? In the first case, it belongs to the Julia set; otherwise it goes to infinity (infinity is an attractor for the point) and we assign a colour to Z depending on the speed the point "escapes" from the origin. In order to produce an image of the whole Julia set associated with C, we must repeat this process for all the points Z whose coordinates are included in this range: -2 < x_coordinate < 2 ; -1.5 < y_coordinate < 1.5

Note that while the Mandelbrot set is connected (i.e. it is a single piece), a Julia set is connected only if it is associated with a point inside the Mandelbrot set. This is just one example of the relationships between the Mandelbrot set and Julia sets.

Example: the Julia set associated with C1 is connected; the Julia set associated with C2 is not connected (see image below).