From 1efbabec9e6e0863d6c5796b9a5cba2871cad2cc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 26 Oct 2014 10:39:43 -0400 Subject: start moving logic out into a separate renderer --- examples/mandelbrot.jl | 15 +++------------ src/FractalExplorer.jl | 1 + src/renderer.jl | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 src/renderer.jl diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl index 2a0aa29..9e8f9fe 100644 --- a/examples/mandelbrot.jl +++ b/examples/mandelbrot.jl @@ -1,23 +1,14 @@ using Tk -using Images using ImageView +using Color using FractalExplorer iterations = 45 imgsize = (640, 480) -img = [ Color.HSV(0, 0, 0) for x=1:imgsize[1], y=1:imgsize[2] ] -mandelbrot = FractalExplorer.Fractal{Float64}(imgsize) - -imgc, imgslice = view(img) - -for i = 1:iterations - FractalExplorer.step(mandelbrot) - new_pixels = (abs(mandelbrot.z) .> 2) & (img .== Color.HSV(0, 0, 0)) - img[new_pixels] = Color.HSV(i * 360/iterations, 1, 1) - view(imgc, img) -end +imgc, imgslice = view([ HSV(0, 0, 0) for x=1:imgsize[1], y=1:imgsize[2] ]) +FractalExplorer.render(imgc, iterations) #If we are not in a REPL if (!isinteractive()) diff --git a/src/FractalExplorer.jl b/src/FractalExplorer.jl index 80142cf..64a52e6 100644 --- a/src/FractalExplorer.jl +++ b/src/FractalExplorer.jl @@ -1,3 +1,4 @@ module FractalExplorer include("fractal.jl") +include("renderer.jl") end diff --git a/src/renderer.jl b/src/renderer.jl new file mode 100644 index 0000000..2fe3ffd --- /dev/null +++ b/src/renderer.jl @@ -0,0 +1,17 @@ +using Tk +using Images +using ImageView +using Color + +function render(imgc, iterations = 45, make_c = z -> z, step = (z, c) -> z.^2 + c) + imgsize = get_size(canvas(imgc)) + img = [ HSV(0, 0, 0) for x=1:imgsize[2], y=1:imgsize[1] ] + f = FractalExplorer.Fractal{Float64}((imgsize[2], imgsize[1]), 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 +end -- cgit v1.2.3-54-g00ecf