3 Julia sets (named after mathematician *Gaston Julia*) are [sets](set.md) of 2D points that are very similar to [Mandelbrot set](mandelbrot_set.md) and just as Mandelbrot set they typically (but not always) have a [fractal](fractal.md) shape. While there is only one Mandelbrot set, there are [infinitely](infinity.md) many Julia sets because in the equation defining Julia set (which has the same format as for Mandelbrot set, just with different variables) there is a parameter we can change to get a different set. Specifically for any [complex number](complex_number.md) (which we may see as a point in 2D plane) there is one Julia set.
5 The **definition** of Julia set will follow (there is actually a more general one, but we'll stick to the narrower, most common one), notice how the equation is similar to that of Mandelbrot set. Initially we pick a constant complex number *c* that will define the whole set; then for each complex number *z* (a point in 2D plane for which we want to see if it belongs to the set or not) we consider the following iteration:
7 *z[n + 1] = z[n]^2 + c*
9 Then we see if under infinitely many iterations this series diverges towards infinity or if it stays bounded. If the point didn't in fact diverge, it belongs to the set, otherwise not. Should we be visualizing the set with a [computer](computer.md), we [approximate](approximation.md) this infinite iteration by performing just a big number of iterations.
11 The following is a picture of one possible Julia set:
14 ___________________________________________________________________
15 | Julia Set for -0.34 - 0.63i :. |
18 | :':::.. '' ::. .. :.' |
19 | '::::. :: :::. . :.'': . |
20 | ......':::.::.:: ...::.:::.::.. . |
21 | :::::::::':'.':.::::::::':.::''::.. |
22 | . '::::'':':::':'':::' ::'' ' |
23 | ':. . .. ..::'::':::. ' :' |
24 | . :: :' ::..::::::: ::: ':::.. ' |
25 | :':::: '.:::::::::'.::::' '' |
26 | .:::::' ':::::::::. ''::::'. |
27 | :. '::::'.::::::::::. '::':.' |
28 | . . '':::. ::: ::::::::'::' .:::: |
29 | :':. ... ':::.:':::'' ' ' ''. |
30 | ..:: .::::::...':.::::::.: |
31 | :::...' '.::::::::'.: .:.:'::::'': |
32 | '' :. : .:''':' :::'::':::. ' ' |
33 | '::'': '' '::: ::''::::: |
38 |___________________________________________________________________|
43 The code below is a simple [C](c.md) program that renders given Julia set into terminal (for demonstrative purposes, it isn't efficient or do any [antialiasing](antialiasing.md)).
50 #define SET_X -0.36 // Julia set parameter
51 #define SET_Y -0.62 // Julia set parameter
54 #define STEP (3.0 / ((double) COLS))
56 unsigned int julia(double x, double y)
58 double cx = x, cy = y, tmp;
60 for (int i = 0; i < 1000; ++i)
62 tmp = cx * cx - cy * cy + SET_X;
63 cy = 2 * cx * cy + SET_Y;
66 if (cx * cx + cy * cy > 10000000000)
75 double cx, cy = FROM_Y;
77 for (int y = 0; y < ROWS; ++y)
81 for (int x = 0; x < COLS; ++x)
84 julia(cx,cy) + (julia(cx,cy + STEP) * 2);
86 putchar(point == 3 ? ':' : (point == 2 ? '\'' :
87 (point == 1 ? '.' : ' ')));