#### Writing Scripts Part #1

Load the script editor and press the New button at the top of the toolbar. Running a blank script
will force the main flame to recalculate, but nothing will change. Before you go any further load
the transform editor and position it so that you can watch it as you run scripts. Type "Rotate(45);"
(without the quotes, but take note of the semi-colon at the end) into the script editor and press
the Run button. You'll see the triangle that's selected in the transform editor rotate by 45 degrees.
If you keep hitting the Run button the triangle will continue to rotate until it gets back its starting
point.

By default scripts are set up to operate on the selected transform, and there are a number of
functions that you can use to change it.

• Rotate(n) rotates the transform by n degrees. Any value for n is acceptable. Positive values
rotate the transform clockwise and negative values rotate it counter-clockwise.
• Scale(n) scales the transform by n. A value of 0.5, for instance, would create a triangle half
the size of the original. Keep the value of n within reasonable bounds. If the triangle of the
selected transform is already close to the size of the reference triangle then you wouldn't it to
get much bigger, and really small transforms don't usually improve the look of a flame.
• Translate(x, y) moves the transform...but not necessarily by x and y.

Here the documentation is going to get fuzzy because the functions mentioned so far use matrix
multiplication, and I'm not up to explaining that at the moment (if I ever will be!). One thing that
it means is that the order of operations is important. Translate(1, 1) will move a triangle of the
same size and position as the reference triangle one unit to the right and one unit upward, but if
you've already scaled the transform by 0.5 then it would only move the transform half a unit to the
right, and half a unit upward. Transforms with triangles that are off to the side, rotated and scaled
arbitrarily, will move in an unpredictable manner. There is a way to move transforms predictably,
but I'll get to that later.

These functions can operate on any transform in the flame, not just the one selected in transform
editor, but you have to tell the script which one you want to be the "active transform". You do this
with the SetActiveTransform method. The format is...

SetActiveTransform(i);

...where i is the index of the transform that you intend to alter. Indexing starts from zero, so to
work on the transform that is labeled 1 in the transform editor you would type
"SetActiveTransform(0);". Once you've done that all further operations will affect only that
transform, until you call SetActiveTransform again with a different index.

Usually you wouldn't use SetActiveTransform with a fixed number (a "constant"), but with a
variable that changes as the script progresses. You see this in most of the example scripts I
supplied. Here's how you would perform the same operation on all of the transforms in a flame
(in this case scaling):

for i := 0 to Transforms - 1 do
begin
SetActiveTransform(i);
Scale(1.1);
end;

You can copy that and paste it into the script editor to see what is does, if you like (there's a
pop-up menu in the script editor with a paste function--Ctrl+V won't work, but Shift+Insert
will). You could also try changing Scale to one of the other functions I've mentioned, or put a
few of them in there (make sure they come after the SetActiveTransform statement, and before the
"end", and don't forget to put the semi-colon at the end of the line).

Index