This is part four of the Beginners Guide to Writing Fractal formulas.
Please do one two and three before doing this tutorial. On a scale
from 1 to 5 1 being easy and 5 being hard this is probably a 3.5. I am
going to take a break from writing tutorials for a day or two for
everyone to digest these 4 tutorials. And are we getting excited about
the julia switch part or what?
that will soon LOL.
In preparation:
Start UF
Load FTtutorial3
Click the edit to open the ufm in the editor
Copy and paste a new instance of FTtutorial3
Change the title of the new instance to FTtutorial4
This tutorial is actually two rolled into one. We are going to do a
simple If elseif loop and enumerate our choices. What does that mean any
ways?
Enumeration is a way of introducing choices in our formula, and making
them available to the enduser. The basic enumeration format is
Param "name"
Caption = "some descriptor"
Enum = "choice1" "choice2" "choice3"b
&.as many as you want
Default = the number of any of your choices (the first choice on your
list is
numbered 0 zero)
endparam
so lets do one for our tests. We have two tests that we can use, the
default test |Z| < 4 and the elliptical test X^2/M^2 + Y^2/N^2 <= 1 so
lets create.
Param FTTEST
Caption = "Bailout Test"
Enum = "Circle" "Ellipse"
Default = 0
End param
That was real easy I hope for everyone.
Lets talk about IF loops. The basic format or an IF..Elseif..Endif
loop is.
IF condition
Do this
Elseif condition
Do this
Endif
You can add as many elseifs and new if's as long as you keep track of
your endifs. So lets apply it to our formula.
At this point I want to introduce a variable called STOP. Its value is
either a one or zero and we will make it our new conditional trap. We want
this condition to let the formula keep on iterating as long as STOP is equal
to zero and stop if its one. Lets comment out the other two balout
condition and add this line to the bailout section:
BAILOUT:
;|Z| < 4
;X^2/M^2 + Y^2/N^2 <=1
stop != 0
Whats that != (surprised equals) doing there?
UF has some logic operators that you need to learn. You know <= and
>=. Let me introduce a couple more.
== means is equal to
!= means not equal to
&& means and when you want to combine two conditions
|| means or when you want to use either condition
! means not and eliminates that condion as a possibility
For now only the == and != matter to us.
Back to our formula, we have introduced a new variable so lets
initialize it in the INIT section by adding
STOP = 0
What we're doing is telling the compiler to set Test=0 every time a new
iteration starts.
How are we going to switch the 0 to a 1?
You must follow carefully now or you'll be lost in the nether world of
logic traps. I will develop the logic slowly. Remember FTTEST we defined
well were gonna use it now.
If @FTTEST == 0
Use the circle trap
Elseif @FTTEST == 1
Use the ellipse trap
Endif
Simple and greatly over complicated by programmers and coders. Let us
figure out how to trip the STOP variable to a 1 for the circle trap only.
If |Z| < 4
Stop=1
Else
Stop=0
Endif
Why did you use an else instead of an elseif?
if i had some other condition that needed to be checked i'd of used an
elseif but i only care about the oposite condition of my test condition.
Hey I know what I'll do, I'll paste this into my if..endif for the
test. Good thinking!
If @FTTEST == 0
If |Z| < 4
Stop=1
Else
Stop=0
End if
Elseif @FTTEST == 1
Use the ellipse trap
Endif
Now I am going to do the same for the elliptical trap.
If X^2/M^2 + Y^2/N^2 <=1
Stop=1
Else
Stop=0
Endif
Paste it into the if..endif for the test
If @FTTEST == 0
If |Z| < 4
Stop=1
Else
Stop=0
End if
Elseif @FTTEST == 1
If X^2/M^2 + Y^2/N^2 <=1
Stop=1
Else
Stop=0
Endif
Endif
OK but where does this go? I can only stick conditionals in the
bailout section. This needs to go into the loop section because that is
where Z,X,Y are being generated so lets put this into the loop section.
So lets review:
We figured out how to make an IF..Else(if)..Endif loop
We created a parameter called FTTEST and enumerated the options
We introduced a variable STOP for our new conditional for bailout
We initialized STOP to zero
And we added the complicated IF..Endif command into the the loop
section.
And now Your formula should look like this:
FTtutorial4{
; 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 + C
X = real(Z)
Y = imag(Z)
M = @FTM
N = @FTN
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
BAILOUT:
STOP != 0
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
Param FTTEST
Caption = "Bailout Test"
Enum = "Circle" "Ellipse"
Default = 0
Endparam
}
this is pretty intense for a tutorial. Writing good formulas is like
building a chiminey you just gotta make sure the bottom bricks are solid.