Update
[less_retarded_wiki.git] / julia_set.md
blob482f38e393420aae14c8ef2d0e09a814bf10964a
1 # Julia Set
3 TODO
5 ```
6  ___________________________________________________________________
7 | Julia Set for -0.34 - 0.63i       :.                              |
8 |                                ..':. ..                           |
9 |                                '':.:'''      ..       ..          |
10 |                                 :':::.. ''  ::.    .. :.'         |
11 |                                  '::::. :: :::. .   :.'': .       |
12 |                              ......':::.::.:: ...::.:::.::.. .    |
13 |                              :::::::::':'.':.::::::::':.::''::..  |
14 |                   .             '::::'':':::':'':::'  ::''  '     |
15 |                   ':.       .   .. ..::'::':::.   '   :'          |
16 |                 . :: :'     ::..::::::: ::: ':::..     '          |
17 |                   :'::::   '.:::::::::'.::::'  ''                 |
18 |                    .:::::' ':::::::::. ''::::'.                   |
19 |                  :. '::::'.::::::::::.  '::':.'                   |
20 |          . .   '':::. ::: ::::::::'::'    .::::                   |
21 |         :':.  ... ':::.:':::''  '  '        ''.                   |
22 |        ..::  .::::::...':.::::::.:                                |
23 |   :::...' '.::::::::'.: .:.:'::::'':                              |
24 |    '' :. : .:''':' :::'::':::.   ' '                              |
25 |         '::'': '' '::: ::'':::::                                  |
26 |          ::       ':.  '' '':::.:                                 |
27 |         ' '       '        ::.:.'.'                               |
28 |                              ::'                                  |
29 |                              '                                    |
30 |___________________________________________________________________|
31 ```
34 # Code
36 The following code 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)).
38 ```
39 #include <stdio.h>
41 #define ROWS 30
42 #define COLS 70
43 #define SET_X -0.36 // Julia set parameter
44 #define SET_Y -0.62 // Julia set parameter
45 #define FROM_X -1.5
46 #define FROM_Y 1.0
47 #define STEP (3.0 / ((double) COLS))
49 unsigned int julia(double x, double y)
51   double cx = x, cy = y, tmp;
53   for (int i = 0; i < 1000; ++i)
54   {
55     tmp = cx * cx - cy * cy + SET_X;
56     cy = 2 * cx * cy + SET_Y;
57     cx = tmp;
59     if (cx * cx + cy * cy > 10000000000)
60       return 0;
61   }
63   return 1;
66 int main(void)
68   double cx, cy = FROM_Y;
70   for (int y = 0; y < ROWS; ++y)
71   {
72     cx = FROM_X;
74     for (int x = 0; x < COLS; ++x)
75     {
76       unsigned int point = 
77         julia(cx,cy) + (julia(cx,cy + STEP) * 2);   
79       putchar(point == 3 ? ':' : (point == 2 ? '\'' : 
80         (point == 1 ? '.' : ' ')));
82       cx += STEP;
83     }
85     putchar('\n');
87     cy -= 2 * STEP;
88   }
90   return 0;
92 ```