Writing Templates for Sprite
Sprite writes the beginning of a formula and simply finishes it off with whatever is in the template file. This guide presumes that you are already proficient at writing Ultra Fractal formulas.
A template file begins with a series of command comment lines that tell Sprite how to behave:
Command comments must use the exact format shown: a semi-colon followed immediately by the command, with nothing else on the line. Other comments can be added on separate lines and they will be ignored.
Sprite writes the image data into an array simply called c, and defines two variables called image_width and image_ height. Valid indices for the array range from c[0, 0] to c[image_width - 1, image_height - 1]
Immediately below the ;begin command the template starts in the Global section of the formula.
The red, green, blue and alpha values for each pixel are packed into a single integer array, and so the integer has to be decoded by the formula. The following code snippet demonstrates how to extract the individual values at location (x, y) in the image:
int rgba = c[x, y]
The color components and alpha values range from 0 to 255 so they need to be divided by 255 before they can be converted to a color variable or used in Ultra Fractal's color functions:
color acolor = rgba(red / 255, green / 255, blue / 255, alpha / 255)
The best way to create a new template is to create a formula using an existing template and edit the formula in Ultra Fractal as you would any new formula. When it's working to your satisfaction copy everything below the image array and paste it into a new text file. You can then create a formula from your new template, work on it some more, and repeat the process as needed.
A hint: rather then scroll through all of the image data to get to the interesting part of the formula, use the shortcut Shift+Ctrl+Down.
Finally you can edit the title of the formula to show the name that you want displayed next to the "Select a template..." button when the template is loaded into Sprite. You do this last because each time you create a formula from the template it will be overwritten by the formula name. Apart from any leading spaces, the format of the title line must be exact: title, space, equals sign, space, opening quotation marks.
You can use the supplied templates as the starting point for your explorations, but bear in mind that these don't necessarily demonstrate the best way to do things. Only the format of the image array is fixed, templates can do anything that you want them to. If you have any suggestions for the improvement of the supplied templates, or to share what you've created, join the Sprite Users Group.