summaryrefslogtreecommitdiffstats
path: root/src/renderer.jl
blob: 45261e4b7cec2c6107f34f8a8c7ad2c20ee4b8a8 (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
33
34
35
36
37
38
39
using Tk
using Images
using ImageView
using Color

function fractal(canvas, make_c, step)
    imgsize = get_size(canvas)
    img = [ HSV(0, 0, 0) for y=1:imgsize[1], x=1:imgsize[2] ]
    view(canvas, img, interactive=false)

    f = FractalExplorer.Fractal{Float64}(imgsize, make_c, step)

    i = 0
    while true
        FractalExplorer.step(f)
        new_pixels = (abs(f.z) .> 2) & (img .== HSV(0, 0, 0))
        img[new_pixels] = HSV(i * 4, 1, 1)
        i = i + 1
        view(canvas, img, interactive=false)
        if length(find(new_pixels)) <= 1
            break
        end
    end

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

function mandelbrot(canvas)
    fractal(canvas, z -> z, (z, c) -> z.^2 + c)
end

function julia(canvas, c = 0)
    fractal(canvas, z -> c, (z, c) -> z.^2 + c)
end