From e4a1e61a88a89930971aa59928481e19d02176dc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 27 Oct 2014 12:35:32 -0400 Subject: automatically calculate the required number of iterations --- examples/mandelbrot.jl | 3 +-- src/renderer.jl | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl index 57637ef..1eb25b0 100644 --- a/examples/mandelbrot.jl +++ b/examples/mandelbrot.jl @@ -4,7 +4,6 @@ using Color using FractalExplorer -iterations = 45 imgsize = (640, 480) win = Toplevel("FractalExplorer", imgsize[1], imgsize[2], false) @@ -15,4 +14,4 @@ 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) +mandelbrot(canvas) diff --git a/src/renderer.jl b/src/renderer.jl index 1eb04b2..45261e4 100644 --- a/src/renderer.jl +++ b/src/renderer.jl @@ -3,18 +3,23 @@ using Images using ImageView using Color -function fractal(canvas, iterations, make_c, step) +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) - for i = 1:iterations + i = 0 + while true FractalExplorer.step(f) new_pixels = (abs(f.z) .> 2) & (img .== HSV(0, 0, 0)) - img[new_pixels] = HSV(i * 360/iterations, 1, 1) + 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()) @@ -25,10 +30,10 @@ function fractal(canvas, iterations, make_c, step) end end -function mandelbrot(canvas, iterations = 45) - fractal(canvas, iterations, z -> z, (z, c) -> z.^2 + c) +function mandelbrot(canvas) + fractal(canvas, z -> z, (z, c) -> z.^2 + c) end -function julia(canvas, iterations = 45, c = 0) - fractal(canvas, iterations, z -> c, (z, c) -> z.^2 + c) +function julia(canvas, c = 0) + fractal(canvas, z -> c, (z, c) -> z.^2 + c) end -- cgit v1.2.3-54-g00ecf