summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-10-28 02:36:56 -0400
committerJesse Luehrs <doy@tozt.net>2014-10-28 02:36:56 -0400
commit88c13f0fe69cc62bbe461e205d8a510e6bc263d3 (patch)
tree71704e1355c40d3fbc2fc6496079ce1ed0f2c2b5
parentf5e418897ab4c1e755d84a8281681b702dec80f9 (diff)
downloadjulia-fractals-88c13f0fe69cc62bbe461e205d8a510e6bc263d3.tar.gz
julia-fractals-88c13f0fe69cc62bbe461e205d8a510e6bc263d3.zip
implement zooming
-rw-r--r--src/fractal.jl19
-rw-r--r--src/renderer.jl14
2 files changed, 26 insertions, 7 deletions
diff --git a/src/fractal.jl b/src/fractal.jl
index f2a9bec..1819df4 100644
--- a/src/fractal.jl
+++ b/src/fractal.jl
@@ -2,6 +2,7 @@ type Fractal{T <: FloatingPoint}
z::Array{Complex{T}, 2}
c::Array{Complex{T}, 2}
step::Function
+ bb::Base.Graphics.BoundingBox
function Fractal(
imgsize::(Integer, Integer),
@@ -12,20 +13,24 @@ type Fractal{T <: FloatingPoint}
(size_x, size_y) = imgsize
aspect_ratio = size_y / size_x
if size_x < size_y
- range_x = (bb.xmin, bb.xmax)
- range_y = (bb.ymin, bb.ymin + (bb.ymax - bb.ymin) * aspect_ratio)
+ scaled_bb = Base.Graphics.BoundingBox(
+ bb.xmin, bb.xmax,
+ bb.ymin, bb.ymin + (bb.ymax - bb.ymin) * aspect_ratio
+ )
else
- range_x = (bb.xmin, bb.xmin + (bb.xmax - bb.xmin) / aspect_ratio)
- range_y = (bb.ymin, bb.ymax)
+ scaled_bb = Base.Graphics.BoundingBox(
+ bb.xmin, bb.xmin + (bb.xmax - bb.xmin) / aspect_ratio,
+ bb.ymin, bb.ymax,
+ )
end
- line_x = linspace(range_x[1], range_x[2], size_x)
- line_y = linspace(range_y[1], range_y[2], size_y)
+ line_x = linspace(scaled_bb.xmin, scaled_bb.xmax, size_x)
+ line_y = linspace(scaled_bb.ymin, scaled_bb.ymax, 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
end
- new(plane, c, step)
+ new(plane, c, step, scaled_bb)
end
end
diff --git a/src/renderer.jl b/src/renderer.jl
index c9290fa..3fefe14 100644
--- a/src/renderer.jl
+++ b/src/renderer.jl
@@ -23,6 +23,20 @@ type FractalCanvas
ImageView.resize(imgc, img2)
end
bind(c, "<Double-Button-1>", (path,x,y)->fractal(c, make_c, step, false))
+ c.mouse.button1press = function(c, x, y)
+ function rubberband_end(c, bb)
+ (size_x, size_y) = tuple(get_size(c)...)
+ line_x = linspace(fc.f.bb.xmin, fc.f.bb.xmax, size_x)
+ line_y = linspace(fc.f.bb.ymin, fc.f.bb.ymax, size_y)
+ plane = [ (x, y) for x=line_x, y=line_y ]
+ bb = Base.Graphics.BoundingBox(
+ plane[bb.xmin, bb.ymin][1], plane[bb.xmax, bb.ymax][1],
+ plane[bb.xmin, bb.ymin][2], plane[bb.xmax, bb.ymax][2],
+ )
+ fractal(c, make_c, step, false, bb)
+ end
+ ImageView.rubberband_start(c, x, y, rubberband_end)
+ end
return fc
end
end