Forums Login/signup

Could anyone explain this code please?

+Pie Number of slices to send: Send
Hi everyone, I hope you're doing good.
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:)
1
+Pie Number of slices to send: Send
Why don't you start by explaining what you think the code, and each of its method, does? Then we can jump in and help when you're getting off course. I think you'll learn more that way.
1
+Pie Number of slices to send: Send
As Tim suggest, it is best you explain the code, as much as possible.
What do you know about the algorithm for the Mandelbrot set? Please look at this t‍‍hread, and any explanations Piet gave you in your earlier t‍‍hread. I cannot remember the algorithm myself, but I do know it has to do with whether the series of numbers diverges or converges from a particular starting point.
When you wrote that code, were you given any instructions about the algorithm?
Why are you writing an Applet? Applets are obsolete. The Applet class has been out of date for at least twenty years; not only is it deprecated (see link on the left) but also, it was superseded by JApplet (also deprecated) about the turn of the century.
Why are you using a mouse listener? Does it give you some sort of starting point for the pattern to expand from?
1
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
 

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!


Thank youuuu very muchhh!!
1
+Pie Number of slices to send: Send
Anduena Smith, it is not necessary to quote the entire previous post when replying.  Just press the Reply button.  See WhenToQuote (that's a link).

reply
reply
This thread has been viewed 787 times.
Similar Threads
Help 3
HELP
HELP2
HELP 5
Hello
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 29, 2025 03:38:52.