Question

I am learning how to make a Julia Set fractal. I am using this as a reference.

I know the math theory behind it very well. I can compute it manually, too. However, what I do not understand is how it is being done in the program mentioned in the reference.

The author has certain variables that determine the zoom and displacement and he performs some calculations on it.

Can someone please explain what they are ?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top