summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-26 00:20:22 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-26 00:20:22 -0400
commit2a174cf7a918637af3f84bf47b2f720dcbc742fe (patch)
tree8cbeb35ad21272bf59af3feda1cf85fe0fbf7bb7
parent3848e2ece1caabc66af3881599e570d752957888 (diff)
downloadjulia-fractals-2a174cf7a918637af3f84bf47b2f720dcbc742fe.tar.gz
julia-fractals-2a174cf7a918637af3f84bf47b2f720dcbc742fe.zip
refactor
this should be able to support both mandelbrot and julia sets
-rw-r--r--examples/mandelbrot.jl8
-rw-r--r--src/Fractal.jl3
-rw-r--r--src/FractalExplorer.jl3
-rw-r--r--src/fractal.jl15
-rw-r--r--src/mandelbrot.jl14
5 files changed, 22 insertions, 21 deletions
diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl
index b127d45..b580478 100644
--- a/examples/mandelbrot.jl
+++ b/examples/mandelbrot.jl
@@ -2,19 +2,19 @@ using Tk
using Images
using ImageView
-using Fractal
+using FractalExplorer
iterations = 45
imgsize = 500
img = [ Color.HSV(0, 0, 0) for x=1:imgsize, y=1:imgsize ]
-m = Fractal.Mandelbrot{Float64}(imgsize)
+mandelbrot = FractalExplorer.Fractal{Float64}(imgsize)
imgc, imgslice = view(img)
for i = 1:iterations
- Fractal.step(m)
- new_pixels = (abs(m.z) .> 2) & (img .== Color.HSV(0, 0, 0))
+ 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
diff --git a/src/Fractal.jl b/src/Fractal.jl
deleted file mode 100644
index 47e1dbf..0000000
--- a/src/Fractal.jl
+++ /dev/null
@@ -1,3 +0,0 @@
-module Fractal
-include("mandelbrot.jl")
-end
diff --git a/src/FractalExplorer.jl b/src/FractalExplorer.jl
new file mode 100644
index 0000000..80142cf
--- /dev/null
+++ b/src/FractalExplorer.jl
@@ -0,0 +1,3 @@
+module FractalExplorer
+include("fractal.jl")
+end
diff --git a/src/fractal.jl b/src/fractal.jl
new file mode 100644
index 0000000..41977c1
--- /dev/null
+++ b/src/fractal.jl
@@ -0,0 +1,15 @@
+type Fractal{T <: FloatingPoint}
+ z::Array{Complex{T}, 2}
+ c::Array{Complex{T}, 2}
+ step::Function
+
+ function Fractal(imgsize, make_c = z -> z, step = (z, c) -> z.^2 + c)
+ line = linspace(-2.0, 2.0, imgsize)
+ plane = [ complex(x, y) for x=line, y=line ]
+ new(plane, make_c(plane), step)
+ end
+end
+
+function step{T <: FloatingPoint}(f::Fractal{T})
+ f.z = f.step(f.z, f.c)
+end
diff --git a/src/mandelbrot.jl b/src/mandelbrot.jl
deleted file mode 100644
index 9cddee7..0000000
--- a/src/mandelbrot.jl
+++ /dev/null
@@ -1,14 +0,0 @@
-type Mandelbrot{T <: FloatingPoint}
- c::Array{Complex{T}, 2}
- z::Array{Complex{T}, 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{T <: FloatingPoint}(m::Mandelbrot{T})
- m.z = m.z.^2 + m.c
-end