aboutsummaryrefslogtreecommitdiff
path: root/examples/mandelbrot.sloth
blob: c52f5de5c504df76887683f696bcc7fa4a10a363 (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
fn main() Int { 
    # Configuration related variables
    var size: Float = 800.0;
    var maxVal = 4.0;
    var maxIter = 50.0;
    var plane = 4.0;

    # Loop over X the configured size
    var x = 0.0;
    while x < size {
        # Loop over Y for the configured size
        var y = 0.0;
        while y < size {
            # Get variables ready
            var cReal = (x * plane / size) - 2.0;
            var cImg = (y * plane / size) - 2.0;
            var zReal = 0.0;
            var zImg = 0.0;
            var count = 0.0;

            # Loop over and finish mandelbrot calculations
            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;

                # Display the mandelbrot to the actual screen
                if as_int(count) == as_int(maxIter) {
                    termpos(as_int(x), as_int(y));
                    print("█");
                }
            }
            y = y + 1.0;
        }
        x = x + 1.0;
    }
    return 0;
}