From 35c239e4b7ab489961a0029a53b505921f230244 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 24 Oct 2014 11:45:40 -0400 Subject: start factoring out into modules --- examples/mandelbrot.jl | 36 ++++++++++++++++++++++++++++++++++++ fractal.jl | 39 --------------------------------------- src/Fractal.jl | 4 ++++ src/complex-plane.jl | 4 ++++ src/mandelbrot.jl | 3 +++ 5 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 examples/mandelbrot.jl delete mode 100644 fractal.jl create mode 100644 src/Fractal.jl create mode 100644 src/complex-plane.jl create mode 100644 src/mandelbrot.jl diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl new file mode 100644 index 0000000..417291d --- /dev/null +++ b/examples/mandelbrot.jl @@ -0,0 +1,36 @@ +using Tk +using Images +using ImageView + +using Fractal + +iterations = 45 +imgsize = 500 + +img = [ Color.HSV(0, 0, 0) for x=1:imgsize, y=1:imgsize ] +c = Fractal.complexplane(4.0, imgsize) +z = c + +imgc, imgslice = view(img) + +for i = 1:iterations + z = Fractal.mandelbrot(z, c) + img[abs(z) .> 2] = Color.HSV(i * 360/iterations, 1, 1) + view(imgc, img) +end + +#If we are not in a REPL +if (!isinteractive()) + + # Create a condition object + cv = Condition() + + # Get the main window (A Tk toplevel object) + win = toplevel(imgc) + + # Notify the condition object when the window closes + bind(win, "", e->notify(cv)) + + # Wait for the notification before proceeding ... + wait(cv) +end diff --git a/fractal.jl b/fractal.jl deleted file mode 100644 index f812f30..0000000 --- a/fractal.jl +++ /dev/null @@ -1,39 +0,0 @@ -using Tk -using Images -using ImageView - -iterations = 90 -imgsize = 1000 - -mandelbrot(z, c) = z.^2 + c - -img = [ Color.HSV(0, 0, 0) for x=1:imgsize, y=1:imgsize ] -c = [ - x + y*im - for x=linspace(-2.0, 2.0, imgsize), y=linspace(-2.0, 2.0, imgsize) -] -z = c - -imgc, imgslice = view(img) - -for i = 1:iterations - z = mandelbrot(z, c) - img[abs(z) .> 2] = Color.HSV(i * 360/iterations, 1, 1) - view(imgc, img) -end - -#If we are not in a REPL -if (!isinteractive()) - - # Create a condition object - cv = Condition() - - # Get the main window (A Tk toplevel object) - win = toplevel(imgc) - - # Notify the condition object when the window closes - bind(win, "", e->notify(cv)) - - # Wait for the notification before proceeding ... - wait(cv) -end diff --git a/src/Fractal.jl b/src/Fractal.jl new file mode 100644 index 0000000..e7f6f2b --- /dev/null +++ b/src/Fractal.jl @@ -0,0 +1,4 @@ +module Fractal +include("complex-plane.jl") +include("mandelbrot.jl") +end diff --git a/src/complex-plane.jl b/src/complex-plane.jl new file mode 100644 index 0000000..ddea80e --- /dev/null +++ b/src/complex-plane.jl @@ -0,0 +1,4 @@ +function complexplane(range, divisions) + line = linspace(-range / 2.0, range / 2.0, divisions) + [ x + y*im for x=line, y=line ] +end diff --git a/src/mandelbrot.jl b/src/mandelbrot.jl new file mode 100644 index 0000000..614d490 --- /dev/null +++ b/src/mandelbrot.jl @@ -0,0 +1,3 @@ +function mandelbrot(z, c) + z.^2 + c +end -- cgit v1.2.3