Could anyone please explain this code in terms of what each method does and how it does the purpose it has?
Thanks a million in advance:)
Piet Souris wrote:hi Anduena,
in the topic that Campbell referred to, I explained what Mandelbrot is all about. In short: the interesting area in the euclidean plane is the square with opposite corners (-2, 2) and (2, -2).
However, to get accurate result, we work with pixelcoordinates (see the lines 'for (x = ...)' and 'for (y = ...). What we must do therefore, is to translate the pixelcoordinates (x, y) to a point in the square (-2, 2) - (2, -2).
This what is happening in these lines:
Next, the color for the pixel (x, y) is calculated here:
and this return value determines the color of the pixel, via the colors array.
Then about the mouseclicks.
Two clicks are noticed: when the mousePressed event happens then the x and Y of that press are stored,
and when the mouseReleased event arrives, the x and y of that event are registered. So now we have the cornerpoints of a new rectangle. But notice that these x and y's are in pixelcoordinates, so that when we recalculate the Mandelbrot for this reduced rectangle, we must calculate new dx's and dy's, taking care that the pixels now represent the smaller new rectangle.
Now, when you zoom into a small rectangle, that rectangle is bound to be close to the border of the Mandelbrot, since that gives spectacular results. However, that means that points that are just outside the Mandelbrot border, require more irterations than we did sofar, to get more colors. That is why the variable 'max' is increased.
Finally: these translations from pixelcoorinates to cartesian coordinates result in pretty hard to follow formulas. Java has the class 'AffineTransform' that can do the hard work for you.
In the other topic, in my last reply, you can see how my code looks, using javaRX Point2D and such an AffineTransform. THe code lmost becomes readable!