Quote:
|
Originally Posted by TheBigDog
I am just a poor boy and my story's seldom told
I have squandered my existance
For a pocket full of fractals such as Mandelbrot
|
The Boxer. I love to whistle along with that song.
Quote:
|
OK Pyro, I've got the formula in front of me, but I am lost about how I begin the calculations. C = a, bi where a and b are any real numbers. I can create the looping formula looking for a value >2. But what gives me the starting value for each point on the space? And what is i?
|
"i" is the square root of minus one. Having said that, ignore it. You will be dealing with ordinary "x,y" coordinates on your display plane.
Assume you have two variables a and b. Where C(0) = a, bi
a and b are the "x,y" points on a small section of the plane around the origin.
Absolute values for a and b need not ever exceed 2, though I use 2.5
So, you have to have two nested loops that look something like:
For a= Alow to Ahigh by Ainc; increment by Ainc
For b= Blow to Bhigh by Binc; increment by Binc
; perform all the iterations of C [below] until either
; number of iterations > IterMax [you're IN the MS, color=Black] or
; asq + bsq > 4. [Avoid taking the square root]
Next b;
Next a;
Now I can answer your question. Where you start is with selecting the low and high values of a -- and the low and high values of b. The increments you will use are determined by the number of pixel columns and pixel rows you will have in your final graphic. Say you choose 640 columns by 520 rows. (I did) And say you start with Alow=-2.5, Ahigh=+2.5, Blow=-2.5, Bhigh=+2.5.
Then Ainc will be 5/640, Binc will be 5/520. This will display the entire MS.
Now let's look at the iteration code INSIDE the double loop above.
Then C(1) = C(0)^2 + C(0)
C(1) = a', b'i, where we have to calculate the new a' and b'
asq = a*a;
bsq = b*b;
a' = asq - bsq + a;
b' = 2*a*b + b;
CntIter = CntIter+1;
newCsquare = asq+bsq;
Your iterations of C(n) stop under either of two conditions:
newCsquare > 4, in which case you plot the point with color CntIter,
or CntIter > IterMax, in which case you plot the point with color Black.
Then you fall into the bottom of the double nested loop, calculate the coordinates of the next pixel in the next column (or the first pixel in the next row) and repeat.
The tricky part in all this is the geometry of your display. Your question reflects that this is indeed the part you tripped on. No shame in that. I had to draw a dozen hand-drawn, pencil-on-paper diagrams showing the relations of my final pixel space, the rectangular subset of the starting MS values
(-2.5<a<2.5;-2.5<b<2.5), the coordinates of the center of my rectangle, and the a-increment and b-increment, before I wrote successful code.
This should get you started. If you get stuck, I'm here.