Fractal Architect 5 Help Index
Applies to:FA 5
See also: Variant Lua Script Catalog
Reference: Lua API Reference for Fractal Architect
Lua is a small, powerful scripting programming language designed to be embedded into applications. You can use it both to create new fractals or modify existing fractals. You don’t have to learn Lua scripting to get full use of the app, but some of you will want to write your own scripts or convert scripts written for Apophysis and JWildfire to Lua.
Especially from the Apophysis community there are hundreds of Apophysis Pascal scripts that can be converted to Lua. Its not hard to convert either Apophysis Pascal or JWildfire Java scripts to Lua.
Please acknowledge the original authors of any scripts you convert in your script comments. Its their hard work that made the script possible.
Fractals have very complex data models with lots of fields and components to be specified.
See: Lua API Reference for Fractal Architect for complete documentation.
Using Lua scripts you can modify any of these components.
Because of this complexity, many scripts will use one of the app’s builtin Lua functions to create a blank fractal, which creates a fractal from a template. Then, you would simply set a handful of parameters to customize the templated fractal.
On the main Welcome to Fractal Architect 5 window, there is a new tab named Scripted Random. Click on that tab to open the Scripted Random working area.
First, you need to select a Main script to produce random fractals with. Do that with the Choose Main Script. It will open the Lua Script Selection Popover.
See: Lua Script Selection/Management Popover.
You can optionally add a Tweak script to modify the newly created Random fractals. Do that with the Optional Tweak Script. It will also open the Lua Script Selection Popover, however only scripts used for tweaking fractals will be shown.
For example, you can select the grayscaleColors script to create grayscale images, instead of the normal random color palettes.
Do unselect a tweak script, just click the Select None to Run button.
You can use Tweak Fractal Lua scripts in these parts of the app:
Fractals can now be saved as a Lua script.
Use the Create Lua Script for Fractal context menu item to save the fractal as a Lua script. It will have a big ugly Uuid as its name (which you can override at the point of saving) or leave the name as is, to remind you that it was created for temporary usage.
There are 2 reasons you might want to save a fractal as a Lua script:
These saved scripts are saved as new Main scripts (not variant tweak scripts).
Go to the main Welcome screen > Make New tab > Random Generation Settings popover. Here you setup the random fractal generator.
You can save these settings as a new main Lua script by clicking on the
Save as Lua Script button.
Later, you can choose that same script on the main Welcome screen > Scripted Random tab.
My Scripts are Lua scripts created by you and are fully editable. You can copy Factory scripts into your My Scripts library and this copy will be editable. You are in fact encouraged to play with the builtin Factory scripts (once they have been copied) and try different parameter value ranges, add new fractal variation types, and learn how to do Lua fractal scripting.
Factory scripts are Lua scripts included with the application. The app treats them everywhere as readonly. The intent is for you to not edit these scripts directly. App updates might include script changes that would overwrite your script changes, if the app allowed factory scripts to be edited.
To make a Factory script editable, you need to first copy it into your My Scripts script library, and then select the copied script and open the builtin text editor.
First, select the Factory script you want to copy. Then click the Copy button (the blue right arrow button). That will make copy of the script into your My Scripts library.
Select the the script in the My Scripts table and then click the Edit button.
Click on the + button to create a new blank script.
Double click the new Unnamed script with mouse. This makes the name editable. Type the new script name.
Click the Edit button to open the builtin text editor.
Select the script to delete from the My Scripts table. Click the - button to delete the script.
Note: Factory scripts cannot be deleted using the app.
Fractal Architect 5 only supports using Lua scripts for:
In the initial release, the scripts all just create a single fractal. To create a batch of new fractals, the script is executed many times, one per new fractal.
In the initial release, the scripts all just modify a single fractal. To modify a batch of fractals, the script is executed many times, one per fractal.
The builtin factory scripts are held inside the app’s runtime container. Apple puts app’s containers inside a hidden directory so they are not intended to hold your important files or your own scripts. App updates might overwrite existing factory scripts.
The My Scripts library is initially also inside the app container, but only because the app can’t create arbitrary folders without you directing the app to do so. It highly encouraged that you choose a new folder for My Scripts at a location you choose.
See: Choose Folder for My Scripts button below and use it to create a folder to hold your My Scripts collection. That new folder location will be saved as an app Preference item. It will also copy Lua scripts from inside the app’s hidden container folder into your new folder.
The library folders have two subfolders:
With most of the fractals, click either Choose Main Script or Choose Tweak Script to open this popover panel.
This panel allows you to select a Lua script to run or to stop running a Lua script by unselecting it (Select None to Run).
FA 5 now supports scripts that have input argument values (that you enter through another panel). There is also a family of scripts that also support picking of varpars (variation instances and their parameter value ranges) .
The most important function of this window is to select one Lua script to run.
When you click on a script name in either the Factory or My Scripts table, the scripts name and which table you click on will be shown in the Run This One: summary at the top of the popover window.
If you want no script to be chosen, click on the Select None to Run button.
For scripts in the Factory table, you can:
Factory scripts cannot be edited. They may be updated by future updates or releases of Fractal Architect.
So, the app allows you to create an editable copy of them.
For scripts in the My Scripts table, you can:
For Variants scripts, the popover provides extra capabilities
You can easily create a list of multiple scripts to run (not just a single script). The list is held in the 3rd table from the left.
Here are the Factory scripts again, grouped by category.
This small table shows either the configured input arguments or configured varpars for the currently selected Lua script.
Many of the builtin scripts included with Fractal Architect, have input arguments. The values of those input arguments will change what the script does.
The script should state what its input arguments are (if any) in comments. But sometimes the script writer forgets to document them.
The FA 5 app Lua runtime, passes to all Lua scripts, these two different Lua tables holding input arguments (by convention).
So if you configure, for example, the scale argument with value of 1.5,
this is passed to the Lua script:
args.scale = 1.5
The script’s code should have a section that loads its input arguments, passed to it by FA 5.
So, lets look at some examples of actual Lua script code fragments that read input arguments.
Example: 1 input argument, named scale with default value of 2.
if args.scale == nil then
args.scale = 2.
end
If the user did not specify a value for the scale argument, then its value is set to the default 2. Otherwise, the script uses the value set by the user in the app.
Script arguments are not limited to numeric values or text strings, they can be Lua expressions.
So this Lua expression:
2.5 + 4.0 * math.random()
is the same as a random number that is between 2.5 and 6.5.
Fractal Architect 5 now provides the capability for a script to have optional input arguments (with default values).
The Script Arguments Panel has 3 tabs:
The idea here is add rows to the table for each of the script’s input arguments. Input arguments are always, by convention, contained in the Lua args table.
The [The Script] tab allows you to see the script itself, so you can discover if it uses input arguments or not. Many scripts do not use them.
Several groups of Lua scripts, in FA 5, now invoke other Lua scripts that are specified as input arguments. Typically, which script(s) are invoked, are configured through one or more input arguments.
By convention, if the parent script invokes just one child script, it would use an input argument name of script.
If the parent script invokes multiple child scripts, the corresponding argument names would be script1, script2 and so forth.
FA 5 provides a group of Lua scripts, which insert one or more variations, plus their parameter value ranges, into transforms.
These scripts all expect to be passed a varpars table from the FA 5 Lua runtime.
This tab shows the actual Lua script so you can see what input arguments it uses.
Fractal Architect has a builtin basic text editor that you can use to edit Lua scripts or Custom Variation’s C code.
Select a script in the My Scripts table. Click the Edit button to open the text editor.
This is a very basic text editor. It has Find & Replace capability using the Find button.
You can do a test compile of the Lua script by clicking the Check Syntax button.
If there are no syntax issues, it will popup a message saying “Lua Syntax OK”.
If syntax errors are found, only first syntax error will be shown in the message.
You can use your own favorite text editor too. Use the Show Folder in Finder to open the My Scripts library folder.
With the popular editor TextMate, you would then drag a file icon, for the file you want to edit, with the mouse and drop it onto the TextMate icon in the Dock.
The Lua Tester window does 4 things:
All print() function output from any Lua script run by the app (anywhere in the app) is displayed here. So if you are developing a Make New fractal script and want to see some calculated result, put a print() function call in the script. When you run the script, its output will be shown here.
You can type in arbitrary Lua commands into the bottom text input field and execute the commands one by one.
Test Make new fractal Lua scripts. When you run these scripts here with the Run File button, it will create a new fractal and put it into the Lua flame global variable.
Test Tweak (Variant) Lua scripts. When you run these scripts here with the Run File button, it will take the Lua flame global variable and modify it.