summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-26 11:32:44 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-26 11:32:44 -0400
commit54a5bb3d9e56bd8290a677ee50700bec422bb94f (patch)
treebc08ebb537ee63634320e3b13840292ea938cb52
parent1efbabec9e6e0863d6c5796b9a5cba2871cad2cc (diff)
downloadjulia-fractals-54a5bb3d9e56bd8290a677ee50700bec422bb94f.tar.gz
julia-fractals-54a5bb3d9e56bd8290a677ee50700bec422bb94f.zip
handle x and y axes properly
julia arrays are stored in column-major order, so the y axis needs to come first
-rw-r--r--examples/mandelbrot.jl2
-rw-r--r--src/fractal.jl19
-rw-r--r--src/renderer.jl4
3 files changed, 13 insertions, 12 deletions
diff --git a/examples/mandelbrot.jl b/examples/mandelbrot.jl
index 9e8f9fe..c73f2c9 100644
--- a/examples/mandelbrot.jl
+++ b/examples/mandelbrot.jl
@@ -7,7 +7,7 @@ using FractalExplorer
iterations = 45
imgsize = (640, 480)
-imgc, imgslice = view([ HSV(0, 0, 0) for x=1:imgsize[1], y=1:imgsize[2] ])
+imgc, imgslice = view([ HSV(0, 0, 0) for y=1:imgsize[2], x=1:imgsize[1] ])
FractalExplorer.render(imgc, iterations)
#If we are not in a REPL
diff --git a/src/fractal.jl b/src/fractal.jl
index d1fd9f6..8b7fa0d 100644
--- a/src/fractal.jl
+++ b/src/fractal.jl
@@ -4,17 +4,18 @@ type Fractal{T <: FloatingPoint}
step::Function
function Fractal(imgsize, make_c = z -> z, step = (z, c) -> z.^2 + c)
- 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)
+ (size_y, size_x) = imgsize
+ aspect_ratio = size_y / size_x
+ if size_x < size_y
+ range_x = (-2.0 * aspect_ratio, 2.0 * aspect_ratio)
range_y = (-2.0, 2.0)
+ else
+ range_x = (-2.0, 2.0)
+ range_y = (-2.0 / aspect_ratio, 2.0 / aspect_ratio)
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 ]
+ line_x = linspace(range_x[1], range_x[2], size_x)
+ line_y = linspace(range_y[1], range_y[2], size_y)
+ plane = [ complex(x, y) for y=line_y, x=line_x ]
c = make_c(plane)
if !isa(c, Array)
c = ones(plane) .* c
diff --git a/src/renderer.jl b/src/renderer.jl
index 2fe3ffd..2d6a213 100644
--- a/src/renderer.jl
+++ b/src/renderer.jl
@@ -5,8 +5,8 @@ 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)
+ img = [ HSV(0, 0, 0) for y=1:imgsize[1], x=1:imgsize[2] ]
+ f = FractalExplorer.Fractal{Float64}(imgsize, make_c, step)
for i = 1:iterations
FractalExplorer.step(f)