Let's take a look at this line (the one below it works the same way):
newRe = (x - w / 2) / (0.5 * zoom * w) + moveX;
(Ignore the lack of 1.5
factor, that's just there to make sure it doesn't look "squished.")
It's in a for
loop that assigns values between 0
and w
to x
.[1] So the leftmost and rightmost newRe
values are going to be:
Leftmost:
newRe = (0 - w / 2) / (0.5 * zoom * w) + moveX; = -(w / 2) / w / 0.5 / zoom + moveX; = -(1 / 2) / 0.5 / zoom + moveX; = -1 / zoom + moveX;
Rightmost:
newRe = (w - w / 2) / (0.5 * zoom * w) + moveX; = (w / 2) / w / 0.5 / zoom + moveX; = (1 / 2) / 0.5 / zoom + moveX; = 1 / zoom + moveX;
Their difference -- that is, the width of the actual rectangle of the Julia fractal being displayed -- is equal to:
(1 / zoom + moveX) - (-1 / zoom + moveX)
= (1 / zoom) - (-1 / zoom)
= 2 / zoom
(This whole calculation also works for newIm
, h
, and moveY
.)
This is why increasing zoom causes the rectangle we're examining to shrink -- which is exactly what "zooming in" is.
[1] It actually only goes to w-1
, but that one-pixel difference makes this calculation a whole lot more difficult.