aboutsummaryrefslogtreecommitdiff
path: root/mandelbrot.java
blob: 1409ce623266a3e4f3b3850c5f3d93a9b21bdcdc (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
33
34
35
36
37
38
39
40
public class mandelbrot {
    public static void main(String[] args) {
                        // char escCode = 0x1B;
                        // System.out.printf("%c[%d;%dH", escCode, 20, 10);
                        // System.out.print("█");
                        // System.out.printf("%c[%d;%dH", escCode, 20, 20);
                        // System.out.print("█");
                        // System.out.printf("%c[%d;%dH", escCode, 30, 10);
                        // System.out.print("█");

        double size = 800;
        double maxVal = 4;
        double maxIter = 50;
        double plane = 4;
        int x = 0;
        while (x < size) {
            int y = 0;
            while (y < size) {
                double cReal = (x * plane / size) - 2.0;
                double cImg = (y * plane / size) - 2.0;
                double zReal = 0.0;
                double zImg = 0.0;
                double count = 0.0;
                while ((zReal * zReal + zImg * zImg) <= maxVal && count < maxIter) {
                    var temp = (zReal * zReal) - (zImg * zImg) + cReal;
                    zImg = 2.0 * zReal * zImg + cImg;
                    zReal = temp;
                    count = count + 1.0;
                    if (count == maxIter) {
                        char escCode = 0x1B;
                        System.out.printf("%c[%d;%dH", escCode, x, y);
                        System.out.print("█");
                    }
                }
                y = y + 1;
            }
            x = x + 1;
        }
    }
}