This is part three of the Beginners Guide to Writing Fractal formulas.
Please do part one and two before doing this tutorial, I won't be
resposible for the ensuing panic.
I was going to do a julia switch but it will be easier after we finish
all the tweaks on this formula. So hold off the exitement you feel for the
Julia switch (LOL). So instead we'll tweak the bail out section a
little.
This may be a little complicated so print it out you'll get more out of
it.
In preparation:
Start UF
Load FTtutorial2
Click the edit to open the ufm in the editor
Copy and paste a new instance of FTtutorial2
Change the title of the new instance to FTtutorial3
Put a semicolon before the |Z|<4 part.
So your new formula should look like this:
FTtutorial3{
; If this tutorial goes any slower I'll have to go to the dentist.
; All right I made the appointment for the dentist
INIT:
Z = #PIXEL
A = @FTA
B = @FTB
C = #PIXEL
LOOP:
Z = A * Z^3 + B * Z + C
BAILOUT:
;|Z| < 4
DEFAULT: ;It's a great habit to just comment
PARAM FTA
Default = (1.0,0.0)
Caption ="Coeff A"
Hint = "A in AZ^3+BZ+C"
Endparam
PARAM FTB
Default = (1.0,0.0)
Caption ="Coeff B"
Hint = "B in AZ^3+BZ+C"
Endparam
}
And now we are ready to play with the bailouts
We arbitrarily chose |Z| <4. This means that basically whenever the
point falls into this circle trap the formula stops iterating, colors the
pixel on the screen and goes to the next point to iterate all over again.
Knowing this, what would happen if we changed the shape of the trap. How much
will it change the resulting fractal image? Lets change it to an elliptical
(egg shaped) trap. A little basic algebra may be required here so grit your
teeth its easy.
Circle x^2 + y^2 = R^2 same as |Z| = 2^2
x is the real portion of the point, y is the imaginary portion and R is
the radius .
The ellipse hase two radiuses one in the x axis and one in the y axis.
We'll call them m and n. Later we can add a center to this ellipse and
put the trap anywhere we want.
Ellipse x^2/m^2 + y^2/n^2 = 1
We'll creat an elliptical trap now
What variables do we need to define?
X the real portion of the number Z
Y the imaginary portion of the number Z
M The length of the axis along the x axis
N the length of the axis along the y axis
Ok, Rui I'm lost at this point so how is this going to help me ?
This is one way of altering the image you see on the screen. If the
math is totally to hard keep at it and ask me or anyone else for help,
I'll do my best to explain it because i know you'll get it and it will
stir up your little gray cells.
So stay with me now. Let's figure out what we need to do
We know the point is Z, and just convneniently UF has builtin functions
to split it apart. We don't need the # because we are calling on a
function not system data.
X=real(Z)
and
Y= imag(Z)
And for M and N we want to create user parameters for them so
Param FTM
Default = 2.0
Caption = "Ellipse Xaxis Width"
Hint = "the xaxis length for the elliptical trap"
Endparam
Param FTN
Default = 1.0
Caption = "Ellipse Yaxis Width"
Hint = "the yaxis length for the elliptical trap"
Endparam
The above and the formula
x^2/m^2 + y^2/n^2 = 1
is all we need.
Lets go to the Default section first and enter our newly defined
parameters M and N.
DEFAULT: ;It's a great habit to just comment
PARAM FTA
Default = (1.0,0.0)
Caption ="Coeff A"
Hint = "A in AZ^3+BZ+C"
Endparam
PARAM FTB
Default = (1.0,0.0)
Caption ="Coeff B"
Hint = "B in AZ^3+BZ+C"
Endparam
Param FTM
Default = 2.0
Caption = "Ellipse Xaxis Width"
Hint = "the xaxis length for the elliptical trap"
Endparam
Param FTN
Default = 1.0
Caption = "Ellipse Yaxis Width"
Hint = "the yaxis length for the elliptical trap"
Endparam
}
Then we will go to the Init section and initialize our new params
INIT:
Z = #PIXEL
A = @FTA
B = @FTB
C = #PIXEL
M = @FTM
N = @FTN
Then we will go to the Loop section and add the definitions we need
LOOP:
Z = A * Z^3 + B * Z + C
X = real(Z)
Y = imag(Z)
And finally we go to the bailout section and add our new test
BAILOUT:
;|Z| < 4
X^2/M^2 + Y^2/N^2 <=1
Hey wait a minute what's up with the <= instead of the =, I'm all
messed up now. Remember we want it to trap. If you left it = it would
only trap the points on the perfect edge of the elipse so by making it <=
we are saying that a point needs to fall inside this egg shaped zone to
stop the iteration.
And off course if you use >= you'd get the blue screen of frustration.
And we're done for now. Your formula should look like this:
FTtutorial3{
; If this tutorial goes any slower I'll have to go to the dentist.
; All right I made the appointment for the dentist
INIT:
Z = #PIXEL
A = @FTA
B = @FTB
C = #PIXEL
M = @FTM
N = @FTN
LOOP:
Z = A * Z^3 + B * Z + C
X = real(Z)
Y = imag(Z)
BAILOUT:
;|Z| < 4
X^2/M^2 + Y^2/N^2 <=1
DEFAULT: ;It's a great habit to just comment
PARAM FTA
Default = (1.0,0.0)
Caption ="Coeff A"
Hint = "A in AZ^3+BZ+C"
Endparam
PARAM FTB
Default = (1.0,0.0)
Caption ="Coeff B"
Hint = "B in AZ^3+BZ+C"
Endparam
Param FTM
Default = 2.0
Caption = "Ellipse Xaxis Width"
Hint = "the xaxis length for the elliptical trap"
Endparam
Param FTN
Default = 1.0
Caption = "Ellipse Yaxis Width"
Hint = "the yaxis length for the elliptical trap"
Endparam
}
Close the editor window and save your work.
Don't get to exited if nothing happens just double check you have the
correct formula loaded. I must have reloaded and re-editted 5 times before I
realized I had the wrong formula loaded.
Wow is this thing getting big or what? and complicated looking to. The
reason I asked you to just put a semicolon in front of the old trap is
because the next chapter we will add some
if
elseif
else
endif
stuff and a little enumeration so we can switch between traps in our formula.