Beginners Guide to Writing Fractal formulas.

What is iteration anyways?
I figured I'd start with a broad description without the math speak.  
The central concept behind computer generated fractal images is 
"Iteration". Iteration is the repetitive application of an algorithm 
to some defined end.  As a simple example if you take a calculator 
and enter a number and then press the square root key repetitively 
will end up at the number 1 or close to it.

So what are the important things for this iteration thing?
1.  Setting the initial conditions required for the iteration. Picking 
    the first number on your calc for instance.
2.  Picking a function that will be iterated Use the sqrt,sin, cos 
    key on the calc
3.  Telling the function when and how to stop
    Save the number after 25 executions of the key stroke or stop when 
    the result is <= 8.5
4.  Tell the compiler what global default values to use radian measure, 
    gradian measure, or degrees.

UF formulas are organized in the exact same way as above.  UF uses 
labels to separate these sections in your formula.  The labels are 
INIT, LOOP, BAILOUT, and DEFAULT.

So how do I write my own formula?
If we are now comfortable with the structure of things we can begin.  
The first thing to worry about is what you are going to call it.  Some 
people use numbers some people use descriptors, and some people use names
of formulas already available.  The key to a successful name is to try and
make the formula name unique to you.  Do not pick "Mandelbrot" as the name of 
your formula or "Shapes" but "MandelRSP01 is good.  RSP001 is weak because 
it offers no hint as to what's included inside.  For this tutorial I've 
selected "FTtutorial".  The next thing to understand is that an ufm file
can contain many individual formulas so we need to separate them for the
compiler.  This is done using "{ }" brackets.  The first stage of writing
a formula looks like this.

FTtutorial{
}

At this point we can put in our labels, remember those INIT, LOOP, 
BAILOUT, and DEFAULT.

FTtutorial{
INIT:
LOOP:
BAILOUT:
DEFAULT:
}

It's a good time to notice that every label must be followed by a colon 
":".  This tells the compiler what to do with the next section.  If you
leave out the colons it doesn't work.  

So what about comments and cryptic messages?
Comments are easy to add just insert a semicolon ";" and the compiler 
will ignore everything after it.  Lets add a comment to the tutorial 
formula.

FTtutorial{
; If this tutorial goes any slower I'll have to go to the dentist.
INIT:
LOOP:
BAILOUT:
DEFAULT:    ;It's a great habit to just comment
}

Just remember that after the ";" the compiler ignores everything.

So how do I pick a function to loop?
There are two ways to pick a function.  Either you know the function 
and want to explore its dynamic or you are a monkey at a keyboard and you
copy it from a math/calculus book.  If you don't have one buy one at the flea
market for 25 cents and it'll serve you greatly.  For this tutorial I
have copied this equation from some pre-calculus book.

    AX^3+BX+C

So what do I do with that now?
First remember that Z is the looping (iterating) variable we are going 
to play with so X becomes Z:

    AX^3+BX+C       becomes

    AZ^3+BZ+C
And oh ya, the compiler does not understand implied operations ( ab is 
the same as a times b, to the compiler ab is its own variable, more on 
variables later) so

    AZ^3+BZ+C                   becomes

    A*Z^3+B*Z+C             and for clarity becomes

      A * Z^3 + B * Z + C         and since we want z to be the value 
of this function every loop lets assign this value to Z

      Z = A * Z^3 + B * Z + C 

Lets put this it into our formula in the loop section. It is 
conventional to indent the lines under the section label 2 spaces.
Remember white space is there to help you the compiler ignores it.  Oh
and by the way I am capitalizing for emphasis you don't have to, the
compiler doesn't know the difference.

FTtutorial{
; If this tutorial goes any slower I'll have to go to the dentist.
INIT:
LOOP:
  Z = A * Z^3 + B * Z + C
BAILOUT:
DEFAULT:    ;It's a great habit to just comment
}

 Before the compiler can actually do anything we need to set initial 
values for the variables in the equation.  The variables are Z, A, B, C so 
lets figure out  what we need to do.

Z   we want this to have the value of the current pixel on the screen 
when we start and conveniently UF offers you a system variable called
PIXEL.  Its important to know that all system variables start with a
pound sign # so the #PIXEL is the current starting screen pixel.  The
only system variable that is not preceded by a # is Z.  Just imagine how
many # you'd be typing.

A, B    some constant that I would like to vary and change to explore 
in the future.  A little later we will  make these selectable but for now
we will make them constants.  It's important how you assign numbers.  If you 
say  A=1 then it is an integer, if A=1.0 Then a floating real number, and
if A=(1.0,0.0) then a complex number.  Integers are quickest, and then 
floats, and then complex as far as the compiler is concerned.  Lets make
ours integers since we are not going to change them yet.

C   Another constant that I think should be constant assigned to the 
#PIXEL variable (its called an arbitrary constant of integration).  Later
on we will use this to apply a Julia switch to the formula.

Lets transfer these assignments to the formula's INIT section.

FTtutorial {
; 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 = 1
  B =  1
  C = #PIXEL
LOOP:
  Z = A * Z^3 + B * Z + C
BAILOUT:
DEFAULT:    ;It's a great habit to just comment
}
 
To recap we've picked the key on the calculator, and what number to 
start with now we have to tell it when to stop.  Think neighborhood now an 
area.  We want it to stop when the absolute value of Z (the distance from
the origin (0.0,0.0)to the point ) is less than &. we'll pick 4 because
if it's good enough for the Mandelbrot set it's at least a good starting
point for us.  So we want | Z | <= 4 So let's put this into our bail out
section.

FTtutorial{
; 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 = 1
  B =  1
  C = #PIXEL
LOOP:
  Z = A * Z^3 + B * Z + C
BAILOUT:
  |Z| < 4
DEFAULT:    ;It's a great habit to just comment
}

What about all the stuff in the DEFAULT section?
We haven't done anything that requires that section yet, be patient.

Well this is great, how do I get it into UF?

It's easy
    Start UF
    Click File-New-Formula
And a window called Formula1 comes up

You normally do all your work in this window.  You can cut and past the 
above formula into this window or type it in from the tutorial.

When you have done it click the little x in the corner and you will get 
"save this file-yes" then a save-as dialogue box.  Save it as FTtut and
hit 
ok.

In UF click
File-New-Fractal

Search out the FTtut and select Fttutorial

And that is your first official Formula

Part 2 to come

In the futur we will be saving all our formulas into this this file so 
don't delete to hastily.