Writing Scripts Part #4

 

In the first part I described a few functions, and how they work on one transform at a time. They
affect the selected transform by default, but you can make them affect a different transform by
using the SetActiveTransform method. I finished by showing you a "for loop" that steps through
all of the transforms used by a flame and changed them in some way.

The Sierpinski script shows a basic example of how to create a specific classic IFS from scratch.
Scripts can be used to create (for instance) your own random flame algorithms.

The "Clear" method clears the flame entirely. After clearing the flame you have to add at least two
transforms for the script to run (you'll get a "Not enough transforms" message otherwise).

Below is script that creates a new random flame every time it is run. This is very similar to one of
the algorithms used internally by Apophysis. It originally comes from the source code to
Chaos: The Software (which is now freeware, and is available form Rudy Rucker's web site). Copy
everything between the rows of asterisks and paste it into the script editor (use Ctrl+V to paste...
the popup menu doesn't seem to work). If you want to save it then call it "Chaos Random.txt".

Now I'll mention a few things that appear in this script...

The Random function returns a random value between 0 and 1. It gives a new value every time it's
called.

This script also uses the cos and sin functions. These are the only math functions available at the
moment. More will become available in a future release.

The constant PI gives you the value of...er...Pi.

You'll see that I'm setting "t" to 3 at the start of the script and then using it in a "for" loop. So this
script will always give you a flame with three transforms. You could change that, but remember
that it has to be between 2 (the minimum number of transforms allowed) and 12 (the maximum).

//**************************************

t := 3;
Clear;
for i := 0 to t - 1 do
begin
  AddTransform;
     r := random * 2 - 1;
  if ((0 <= r) and (r < 0.2)) then
    r := r + 0.2;
  if ((r > -0.2) and (r <= 0)) then
    r := r - 0.2;
  s := random * 2 - 1;
  if ((0 <= s) and (s < 0.2)) then
    s := s + 0.2;
  if ((s > -0.2) and (s <= 0)) then
    s := s - -0.2;
  theta := PI * random;
  phi := (2 + random) * PI / 4;
  with Transform do
  begin
    a := r * cos(theta);
    b := s * (cos(theta) * cos(phi) - sin(theta));
    c := r * sin(theta);
    d := s * (sin(theta) * cos(phi) + cos(theta));
    e := 1 + 0.3 * random;
    f := 1 + 0.3 * random;
  end;
end;
for i := 0 to Transforms - 1 do
begin
  SetActiveTransform(i);
  Transform.Color := i / (Transforms - 1);
  Transform.Weight := 1 / Transforms;
end;
ResetLocation := True

//**************************************

Index