hd1.gif - 9Kb



demo1.gif - 1805 bytes

All the examples used here are available in a zip archive which you can download. To run a CompoScript file you just have to drag and drop it onto either the Canvas or !Compo’s icon bar icon. To get started, try dragging the first example “demo1” and dropping it onto the canvas. This should create an angled greeting in red Homerton font.

CompoScript files are basically text files so you can load the script into an editor and examine it. If you do, “demo1” Looks as follows:


#CompoScript

let myname = "Greetings!"
let red = &FF0000
let fangle = 33
let xpos = 100
let ypos = 100

maketext "demotext1"
{
 Text: <myname>
 Font: Homerton.Bold
 Size: 32
 At: <xpos> <ypos>
 Angle: <fangle>
 Colour: <red>
 Border: 16x16
}

end


The meanings of each of the instructions in the file should be fairly clear from seeing the result. The first line is “#CompoScript”. This declares that the file is set of CompoScript instructions. More generally, the “#” can be used at the beginning of a line to indicate a comment. The next few lines use the instruction “let” to set some numerical values. These are followed by one of the inbuilt functions, “maketext”.

The string that follows the “maketext” sets the name Compo will assign to the created object. (If you select the object on the Compo canvas and call up the menu it will show the name beside the “edit” entry.) You can the set various of the object’s attributes by including appropriate statements in between curly braces that follow the “maketext” line. So, for example, “Size: 32” sets the font size to 32 points. Values for colours are in “HTML format” – i.e. a hex integer in the general form &RRGGBB.

Note that you can give simple numerical values as in the “Border: 16x16” line, or can use the current values of variables by giving their name enclosed in angle brackets – e.g. as in the line “At: <xpos> <ypos>”. In each case the attribute name is given at the start of the line, then a colon is used to separate this from the value(s).

demo1b.gif - 2793 bytes


Where more than one value may be given they can be separated by a space, or a comma, or by an ‘x’, whichever you prefer. In some cases you only have to give one value, but two can also be specified. For example, drop the CompoScript file “demo1b” onto the canvas and notice the differences. As well as a different location, angle, colour, and font, the text has its aspect ratio changed. This is due to the line “Size: 32 16” in the maketext attributes. The first value indicates the nominal width of characters, the second the height. When only one value is given it is assumed to apply for both. Attributes which are omitted will generally default to sensible values, so — for example — if you omit the line specifying the text angle, a value of zero (i.e. horizontal) would be assumed.

Having seen an example of a text creation script, lets now look at a script that can alter an existing object. Check that both the text objects “demotext1” and “demotext1b” that you have created are visible on the canvas. Drop the script file “shadow1” onto the canvas and watch what happens. You should see the red greetings develop a soft shadow!

shad1.gif - 6Kb


The script that produces this effect is as follows.

#CompoScript

select "demotext1"

let .shadow = 1

makemask SHADOW copy BLEND
processmask SHADOW Antialias Smudge AllButBlack
processmask SHADOW Edge Maximum
processmask SHADOW Antialias Smudge All

end


The script first selects the object named “demotext1”. From then on until some other object is selected, any object processes will be applied to this selected object. The next instruction makes use of one of the implicit parameters that allow the script to access the properties of objects. These are all distinguished from general variables by beginning with a “.” character. The line “let .shadow = 1” specifies that the object now has a visible shadow. By default the BLEND mask pattern is used for the shadow shape unless you explicitly create a distinct shadow mask. You can hide an object’s shadow using “let .shadow = 0”. However this does not actually remove the mask data, so a later “let .shadow = 1” applied to the object will cause the shadow to reappear. These commands are the direct equivalent of ticking or unticking the shadow option tick button.

The “makemask” line copies the pattern of the BLEND mask (used for controlling transparency) into the SHADOW. Initially this has no obvious visible effect, but it means there is now a distinct mask pattern for the shadow which can be manipulated independently of the blend mask. The following series of “processmask” lines then manipulate the mask which they specify (i.e. the SHADOW mask in each case). If you compare the instructions that follow the mask’s name on each of these lines you’ll find that they are the same as those given in Compo’s menu’s for mask processes, but with any spaces removed. Hence they apply the same effects which you could chose, by hand, via the menus. The advantage of applying them using the above script is that you can apply a chosen series of effects and settings in one simple operation.

It is worth saying at this point that in general, variable names in CompoScript are all case insensitive. So using upper case for BLEND and SHADOW in the above script is purely for clarity when reading. You can mix and use cases as you wish. Case only becomes significant in procedure names or when a string is in quotes.

When working with just one named object this ability to perform multiple operations isn’t particularly useful as it implies writing a script for every individual object. However CompoScript is more flexible than this. Clear the canvas and drop both “demo1” and “demo1b” onto it to recreate the original text objects.

shad1s.gif - 5Kb


Now select just one of the objects, then drop the script file “shadow1s” onto the canvas. This time only the selected object will be changed. If you examine the script file you’ll see that this is because the file doesn’t itself select an object, it just acts upon the first object it finds which is already selected. If no objects have been selected Compo will pop up a window informing you this is the case. If you now select the other object and drop the “shadow1s” script file onto the canvas the newly selected object will now be processed. If you wished, you could now apply this shadowing process as you chose to one new object after another on a complex canvas.




prevpage.gif - 1296 bytes homecc2.gif - 8Kb nextpage.gif - 1271 bytes


Content and pages maintained by: Jim Lesurf
using HTMLEdit, Compo, and TechWriter.