aboutsummaryrefslogtreecommitdiff
path: root/mandelbrot.c
blob: a6eff9ee5c6972afc346c5b9d98323ed7bb61686 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>

int main() {
    float size = 800.0;
    float maxVal = 4.0;
    float maxIter = 50.0;
    float plane = 4.0;
    int x = 0;
    while (x < size) {
        int y = 0;
        while (y < size) {
            float cReal = (x * plane / size) - 2.0;
            float cImg = (y * plane / size) - 2.0;
            float zReal = 0.0;
            float zImg = 0.0;
            float count = 0.0;
            while ((zReal * zReal + zImg * zImg) <= maxVal && count < maxIter) {
                float temp = (zReal * zReal) - (zImg * zImg) + cReal;
                zImg = 2.0 * zReal * zImg + cImg;
                zReal = temp;
                count = count + 1;
                if (count == maxIter) {
                    printf("\x1b[%d;%dH", x, y);
                    printf("█");
                }
            }
            y = y + 1;
        }
        x = x + 1;
    }
    return 0;
}