summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/mandelbrot.jl7
-rw-r--r--src/mandelbrot.jl15
2 files changed, 16 insertions, 6 deletions
diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl
index 417291d..ab618d4 100644
--- a/examples/mandelbrot.jl
+++ b/examples/mandelbrot.jl
@@ -8,14 +8,13 @@ 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
+m = Fractal.Mandelbrot(imgsize)
imgc, imgslice = view(img)
for i = 1:iterations
- z = Fractal.mandelbrot(z, c)
- img[abs(z) .> 2] = Color.HSV(i * 360/iterations, 1, 1)
+ Fractal.step(m)
+ img[abs(m.z) .> 2] = Color.HSV(i * 360/iterations, 1, 1)
view(imgc, img)
end
diff --git a/src/mandelbrot.jl b/src/mandelbrot.jl
index 614d490..bde0a74 100644
--- a/src/mandelbrot.jl
+++ b/src/mandelbrot.jl
@@ -1,3 +1,14 @@
-function mandelbrot(z, c)
- z.^2 + c
+type Mandelbrot
+ c::Array{Complex{Float64}, 2}
+ z::Array{Complex{Float64}, 2}
+
+ Mandelbrot(imgsize) = (
+ line = linspace(-2.0, 2.0, imgsize);
+ plane = [ x + y*im for x=line, y=line ];
+ new(plane, plane)
+ )
+end
+
+function step(m::Mandelbrot)
+ m.z = m.z.^2 + m.c
end