summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-26 10:25:56 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-26 10:25:56 -0400
commitf6438aa63834ed6ed577863133d2ca01700f2f1f (patch)
tree70ec5946cfe0ce738f11c5dda05efe9f78e602dd
parentfb9498f1295089ac50c65d9ea826bc26acb521b0 (diff)
downloadjulia-fractals-f6438aa63834ed6ed577863133d2ca01700f2f1f.tar.gz
julia-fractals-f6438aa63834ed6ed577863133d2ca01700f2f1f.zip
handle non-square windows
-rw-r--r--examples/mandelbrot.jl4
-rw-r--r--src/fractal.jl13
2 files changed, 13 insertions, 4 deletions
diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl
index b580478..2a0aa29 100644
--- a/examples/mandelbrot.jl
+++ b/examples/mandelbrot.jl
@@ -5,9 +5,9 @@ using ImageView
using FractalExplorer
iterations = 45
-imgsize = 500
+imgsize = (640, 480)
-img = [ Color.HSV(0, 0, 0) for x=1:imgsize, y=1:imgsize ]
+img = [ Color.HSV(0, 0, 0) for x=1:imgsize[1], y=1:imgsize[2] ]
mandelbrot = FractalExplorer.Fractal{Float64}(imgsize)
imgc, imgslice = view(img)
diff --git a/src/fractal.jl b/src/fractal.jl
index eb0b496..d1fd9f6 100644
--- a/src/fractal.jl
+++ b/src/fractal.jl
@@ -4,8 +4,17 @@ type Fractal{T <: FloatingPoint}
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 ]
+ aspect_ratio = imgsize[2] / imgsize[1]
+ if imgsize[1] < imgsize[2]
+ range_x = (-2.0, 2.0)
+ range_y = (-2.0 * aspect_ratio, 2.0 * aspect_ratio)
+ else
+ range_x = (-2.0 / aspect_ratio, 2.0 / aspect_ratio)
+ range_y = (-2.0, 2.0)
+ end
+ line_x = linspace(range_x[1], range_x[2], imgsize[1])
+ line_y = linspace(range_y[1], range_y[2], imgsize[2])
+ plane = [ complex(x, y) for x=line_x, y=line_y ]
c = make_c(plane)
if !isa(c, Array)
c = ones(plane) .* c