less_retarded_wiki/julia_set.md
Miloslav Ciz c44e879a84 Update
2022-05-12 20:53:59 +02:00

93 lines
2.8 KiB
Markdown

# Julia Set
TODO
```
___________________________________________________________________
| Julia Set for -0.34 - 0.63i :. |
| ..':. .. |
| '':.:''' .. .. |
| :':::.. '' ::. .. :.' |
| '::::. :: :::. . :.'': . |
| ......':::.::.:: ...::.:::.::.. . |
| :::::::::':'.':.::::::::':.::''::.. |
| . '::::'':':::':'':::' ::'' ' |
| ':. . .. ..::'::':::. ' :' |
| . :: :' ::..::::::: ::: ':::.. ' |
| :':::: '.:::::::::'.::::' '' |
| .:::::' ':::::::::. ''::::'. |
| :. '::::'.::::::::::. '::':.' |
| . . '':::. ::: ::::::::'::' .:::: |
| :':. ... ':::.:':::'' ' ' ''. |
| ..:: .::::::...':.::::::.: |
| :::...' '.::::::::'.: .:.:'::::'': |
| '' :. : .:''':' :::'::':::. ' ' |
| '::'': '' '::: ::''::::: |
| :: ':. '' '':::.: |
| ' ' ' ::.:.'.' |
| ::' |
| ' |
|___________________________________________________________________|
```
# Code
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)).
```
#include <stdio.h>
#define ROWS 30
#define COLS 70
#define SET_X -0.36 // Julia set parameter
#define SET_Y -0.62 // Julia set parameter
#define FROM_X -1.5
#define FROM_Y 1.0
#define STEP (3.0 / ((double) COLS))
unsigned int julia(double x, double y)
{
double cx = x, cy = y, tmp;
for (int i = 0; i < 1000; ++i)
{
tmp = cx * cx - cy * cy + SET_X;
cy = 2 * cx * cy + SET_Y;
cx = tmp;
if (cx * cx * cy * cy > 10000000000)
return 0;
}
return 1;
}
int main(void)
{
double cx, cy = FROM_Y;
for (int y = 0; y < ROWS; ++y)
{
cx = FROM_X;
for (int x = 0; x < COLS; ++x)
{
unsigned int point =
julia(cx,cy) + (julia(cx,cy + STEP) * 2);
putchar(point == 3 ? ':' : (point == 2 ? '\'' :
(point == 1 ? '.' : ' ')));
cx += STEP;
}
putchar('\n');
cy -= 2 * STEP;
}
return 0;
}
```