Scripting tutorial #4: Breaking Things Down Further
Quick Refresher
Here's the script you ran as part of the tutorial's previous page again:
START FILTER.GROW FILTER.GROW BUMP tCOLOR.NEW 0x5555FF STORE BLUE COLOR.NEW 0x000000 STORE BLACK COLOR.NEW 0xFFFFFF STORE WHITE FILTER.SWAP BLACK BLUE FILTER.SWAP WHITE .ALPHA END
On this page, we'll go back over this script, line by line, to show how everything works.
Breaking it down
START
Every script needs to tell the editor where the script's code begins. This is done by using the START command, which takes no parameters. This might seem strange or maybe even redundant now, but in a bit you'll learn about Functions and Labels and all sorts of things like that. These change which lines get executed next, so something needs to anchor the start of the script, and a special command keeps makes it very easy to find.
In more formal languages, the "main" function performs the same job as the START command.
FILTER.GROW FILTER.GROW
The FILTER.GROW command runs the Grow Foreground Color Filter. Each time this command is used, the foreground color grows by one step. Since this is called twice, the foreground color should grow by two steps.
BUMP
The BUMP command is very special. It places the current image into a hidden stack, and then copies the original image back onto the working image. This allows your scripts to create layered effects.
COLOR.NEW 0x5555FF
How colors are stored in the editor isn't exactly intuitive, so instead of using raw integers or color values to indicate different colors, you'll need to create a color "object" using COLOR.NEW or IMAGE.GETPIXEL. COLOR.NEW can accept either one or three parameters; in these examples, the hexadecimal color value is used to create the color object. These hexadecimal values are identical to how you'd specify a color in HTML or CSS - 0x5555FF is the light blue color in the editor's default palette.
STORE BLUE
The COLOR.NEW command returns the new color object, so we need to save it somewhere for later use. The STORE command saves a value in a "pocket", called a variable. In this example, the value is understood to be .RESULT, a special variable that stores the result of the last operation, and it's being placed into the variable named BLUE. Variable names are not case sensitive, so BLUE, blue, and Blue are all going to refer to the same variable.
COLOR.NEW 0x000000 STORE BLACK COLOR.NEW 0xFFFFFF STORE WHITE
More of the same, this time preparing the black and white colors.
FILTER.SWAP BLACK BLUE FILTER.SWAP WHITE .ALPHA
FILTER.SWAP is the command for the Change Foreground to Background Color Filter. This filter swaps one color for another. On the first line, it changes black pixels into blue ones. On the second, it changes white pixels into transparent pixels. Like .RESULT, .ALPHA is a special placeholder that's always available. It holds a special color value that represents transparency. It's called .ALPHA because transparency is also known as an alpha channel.
END
Finally, the END command marks the end of the script. Upon reaching this command, the scripting engine will stop, merge all of the BUMP'd layers together, and exit, leaving you with your altered image. END also marks the end of a function; seeing how START is equivalent to a specific function in other languages, this parallel should be self-explanatory.
On to the next tutorial page -->
<-- Back to the previous tutorial page