This is part five of the Beginners Guide to Writing Fractal formulas.
Please do one, two, three and four before doing this tutorial.
For this Tutorial lets add an assignable center to our traps so we can
move the shape around the complex plane and add a selectable function
( a selectable function you say hmmm.)
In preparation:
Start UF
Load FTtutorial4
Click the edit to open the ufm in the editor
Copy and paste a new instance of FTtutorial4
Change the title of the new instance to FTtutorial5
So lets add a center to the elliptical trap first.
We know from the last tutorial that the equation for the elliptical trap
is
X^2/M^2 + Y^2/N^2 <=1
Trust me on this one...The center of the above trap is (0,0)
From analytical geometry (high school algebra,conic sections) we have
(X-H)^2/M^2 + (Y-K)^2/N^2 = 1
This is the equation of an ellipse centered at (H,K) with one axis M units
wide and another axis N units tall.
Great, that makes me feel all warm and fuzzy what do I do with that.
First lets analyze the variables
X Our formula already takes care of it
Y Our formula already takes care of it
H A new one we have to figure out
K Another new one we have to figure out
We want to add a new parameter called Center
Param Center
Caption = "Trap Center"
Hint = "The center of the elliptical trap\
And the Cirle trap"
Default = (0.0,0.0)
Endparam
Whats that back slash "\" doing there is that a typo?
That backslash is how you tell the compilor that the Hint string or
any other string is continued on the next line. Very useful for big long
winded hints or long enumerations.
A really neat thing is that the order you put your parameter definitions
in the formula default section is the order they will display in in the
properties/formula tab dropdown.
Hopefully defining a new parameter is old hat and every one can do it.
Lets put this into our formula in the default section. ( You can do that
all on your own now)
We've defined the parameter Center how do we use it now?
We are going to take advantage of the real and imag functions in UF and
define.
H = real(@Center)
K = imag(@Center)
We need to insert these into our loop section. The loop section now looks
like this:
LOOP:
Z = A * Z^3 + B * Z + C
X = real(Z)
Y = imag(Z)
M = @FTM
N = @FTN
H = real(@Center)
K = imag(@Center)
IF @FTTEST == 0
if |Z| < 4
STOP =1
else
STOP =0
endif
Elseif @FTTEST == 1
if X^2/M^2 + Y^2/N^2 <=1
STOP =1
else
STOP =0
Endif
Endif
Hey, why did you put the H and K assignments before the if else statement?
We did that because the compiler is sequential and we will need this info
before the if statement so it will work properly.
We have one quick substitution to make. We need to replace
X^2/M^2 + Y^2/N^2
With
(X-H)^2/M^2 + (Y-K)^2/N^2
Lets do that. The loop section now looks like:
LOOP:
Z = A * Z^3 + B * Z + C
X = real(Z)
Y = imag(Z)
M = @FTM
N = @FTN
H = real(@Center)
K = imag(@Center)
IF @FTTEST == 0
if |Z| < 4
STOP =1
else
STOP =0
endif
Elseif @FTTEST == 1
if (X-H)^2/M^2 + (Y-K)^2/N^2 <=1
STOP =1
else
STOP =0
Endif
Endif
And that is it we have added a selectable center to the elliptical trap.
The circle trap will be easier to do now since we have already defined
everything we need. Lets look at the Circle trap closely. Remember back
in chapter one when I said that:
|Z| < 4 is basically the same as saying X^2 + y^2 < 4
We're going to take advantage of this and do the same substitution we did
to the elleptical trap.
Lets replace
X^2 + Y^2 < 4
With
(X-H)^2 + (Y-K)^2 < 4
Lets put that into our Formula's Loop section. The Loop section now looks
like this:
LOOP:
Z = A * Z^3 + B * Z + C
X = real(Z)
Y = imag(Z)
M = @FTM
N = @FTN
H = real(@Center)
K = imag(@Center)
IF @FTTEST == 0
if (X-H)^2 + (Y-K)^2 < 4
STOP =1
else
STOP =0
endif
Elseif @FTTEST == 1
if (X-H)^2/M^2 + (Y-K)^2/N^2 <=1
STOP =1
else
STOP =0
Endif
Endif
Lets save our work.
Close he formula editor
Formula tab then select FTTutorial5
and try out this new Center thing.
Next we are goung to add a selectable function in our formula. This is
where you get a big bang for you buck. These function calls have a similar
structure to the Parameter blocks. It is:
Func name
Caption = "yada yada"
Hint = "yoda yoda"
Default = sqr()
Endfunc
Pretty straight forward. Lets take a look at our formula and figure out
where to put a function. The function being iterated is:
Z = A * Z^3 + B * Z + C
Lets change it to
Z = A * Z^3 + B * Z + (some function of C)
Lets Define our new function
Func FTFUNC
Caption = "C Function"
Hint = " This changes the value of \
C ,the pixel, and actually \
Grabs the point from another\
Projected plane" ; I warned you wordy hints
Default = Ident()
Endfunc
A quick question: what's the IDENT thing?
This is one of the functions available to us. Its called the identity
function and returns the same value its fed. This function does
absolutely nothing to the pixel. This is why i chose it to be the
default so that
the picture generated is the standard picture. The other functions are
listed below.
Sin asin sinh asinh
cos acos cosh acosh
tan atan atan2 tanh atanh
cotan cotanh
sqr sqrt
log exp
abs cabs
conj flip
ident zero
recip ceil floor trunc
round real imag oldz
So lets add this function definition to our Default section.
Then we can change in our loop section:
Z = A * Z^3 + B * Z + C
to
Z = A * Z^3 + B * Z + @FTFUNC(C)
Did you notice that to use a defined function we use the @ just like we
use the @ in front of our defined parameters. So the Formula looks like
this now:
FTtutorial5{
; 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
STOP = 0
LOOP:
Z = A * Z^3 + B * Z + @FTFUNC(C)
X = real(Z)
Y = imag(Z)
M = @FTM
N = @FTN
H = real(@Center)
K = imag(@Center)
IF @FTTEST == 0
if (X-H)^2 + (Y-K)^2 < 4
STOP =1
else
STOP =0
endif
Elseif @FTTEST == 1
if (X-H)^2/M^2 + (Y-K)^2/N^2 <=1
STOP =1
else
STOP =0
Endif
Endif
BAILOUT:
STOP != 0
DEFAULT: ;It's a great habit to just comment
PARAM FTA
Default = (1.0,0.0) ; this tells the UF compiler that it is a
complex
number
Caption ="Coeff A"
Hint = "A in AZ^3+BZ+C"
Endparam
PARAM FTB
Default = (1.0,0.0) ; this tells the UF compiler that it is a
complex
number
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
Param FTTEST
Caption = "Bailout Test"
Enum = "Circle" "Ellipse"
Default = 0
Endparam
Param Center
Caption = "Trap Center"
Hint = "Center of the Elliptical Trap\
an the Circle Trap"
Default = (0.0,0.0)
Endparam
Func FTFUNC
Caption = "C Function"
Hint = "This changes the value of \
C the pixel, and actually \
Grabs the point from another \
plane projected by this function" ; I warned you wordy hints
Default = Ident()
Endfunc
}
Lets save our work.
Close the formula editor
Reload the formula
See the new C function drop down
Try out this new Function thing and enjoy.
This brings chapter five to an end. I guess the other tutorials are going
well because i'm not being bombarded with flame mail. Will the next
chapter be the Julia switch chapter....(Cheerleaders cheering RAH! RAH!
RAH! SIS! BOOM! BAH!)...Maybe a few more formula tweaks and additions.
then the julia switch.