From 185cb5af4a9221025b3cc1999651e30938b7386e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 27 Oct 2014 12:20:20 -0400 Subject: draw into our own window --- examples/mandelbrot.jl | 11 +++++++++-- src/renderer.jl | 18 ++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl index 9bcc818..57637ef 100644 --- a/examples/mandelbrot.jl +++ b/examples/mandelbrot.jl @@ -7,5 +7,12 @@ using FractalExplorer iterations = 45 imgsize = (640, 480) -imgc, imgslice = view([ HSV(0, 0, 0) for y=1:imgsize[2], x=1:imgsize[1] ]) -mandelbrot(imgc, iterations) +win = Toplevel("FractalExplorer", imgsize[1], imgsize[2], false) +frame = Frame(win) +pack(frame, expand=true, fill="both") +canvas = Canvas(frame, imgsize[1], imgsize[2]) +pack(canvas, expand=true, fill="both") +set_visible(win, true) +view(canvas, [ 0.0 for y=1:imgsize[2], x=1:imgsize[1] ], interactive=false) + +mandelbrot(canvas, iterations) diff --git a/src/renderer.jl b/src/renderer.jl index 372353a..be70ae7 100644 --- a/src/renderer.jl +++ b/src/renderer.jl @@ -3,30 +3,32 @@ using Images using ImageView using Color -function renderfractal(imgc, iterations, make_c, step) - imgsize = get_size(canvas(imgc)) +function renderfractal(canvas, iterations, 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) 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) + view(canvas, img, interactive=false) end if (!isinteractive()) cv = Condition() - win = toplevel(imgc) + win = Tk.toplevel(canvas) bind(win, "", e->notify(cv)) wait(cv) end end -function mandelbrot(imgc, iterations = 45) - renderfractal(imgc, iterations, z -> z, (z, c) -> z.^2 + c) +function mandelbrot(canvas, iterations = 45) + renderfractal(canvas, 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) +function julia(canvas, iterations = 45, c = 0) + renderfractal(canvas, iterations, z -> c, (z, c) -> z.^2 + c) end -- cgit v1.2.3