summaryrefslogtreecommitdiffstats
path: root/src/renderer.jl
blob: 372353ab3c9b234e15b08e7def97fc5958f2b4ea (plain) (blame)
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
using Tk
using Images
using ImageView
using Color

function renderfractal(imgc, iterations, make_c, step)
    imgsize = get_size(canvas(imgc))
    img = [ HSV(0, 0, 0) for y=1:imgsize[1], x=1:imgsize[2] ]
    f = FractalExplorer.Fractal{Float64}(imgsize, make_c, step)

    for i = 1:iterations
        FractalExplorer.step(f)
        new_pixels = (abs(f.z) .> 2) & (img .== HSV(0, 0, 0))
        img[new_pixels] = HSV(i * 360/iterations, 1, 1)
        view(imgc, img)
    end

    if (!isinteractive())
        cv = Condition()
        win = toplevel(imgc)
        bind(win, "<Destroy>", e->notify(cv))
        wait(cv)
    end
end

function mandelbrot(imgc, iterations = 45)
    renderfractal(imgc, iterations, z -> z, (z, c) -> z.^2 + c)
end

function julia(imgc, iterations = 45, c = 0)
    renderfractal(imgc, iterations, z -> c, (z, c) -> z.^2 + c)
end