~mikelma/oktac

oktac/examples/mandelbrot/mandelbrot.ok -rw-r--r-- 765 bytes
79afb735 — mikelma basic lambda function support 7 months ago
                                                                                
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
extern fun printf(&u8, ...)

fun mandelbrot(a: f64, b: f64): f64 {
    let za = 0.0; let zb = 0.0;
    for let i=0; i<50; i=i+1 {
        # (a+bi)(c+di) = (ac−bd) + (ad+bc)i
        za = (za*za - zb*zb) + a;
        zb = (za*zb + za*zb) + b;
    }
    ret za*za + zb*zb;
}

fun main(): i16 {
    let xstart = -2.0;
    let xend = 0.5;
    let ystart = 1.0;
    let yend = -1.0;

    let xstep = 0.0315;
    let ystep = -0.05;

    let x = xstart;
    let y = ystart;

    while y > yend {
        x = xstart;
        while x < xend {
            if mandelbrot(x, y) < 4.0 {
                printf(@cstr("x"));
            } else { printf(@cstr(" ")); }
            x = x + xstep; 
        }
        printf(@cstr("\n"));
        y = y + ystep; 
    }
    ret 0;
}