Table Of Contents
Graphics are programmed using a general purpose scripting language. To see examples view the ► menu which shows scripted and animated examples that are ready to drag and drop for use. The scripting language can be extended using a Plugin. The goal is to keep it simple yet very powerful. Before delving into serious programming issues, lets take a look at a script to animate setting colors of a circle.
/* Declarations */
@@class() Circle:Object
@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)release;
@@end
/* Execution Block */
{
id myCircle;
int ii;
unsigned animationCount;
double red, green;
myCircle = [[Circle alloc] init];
animationCount = [myCircle animationCount];
red = (animationCount % 10) / 10.0;
green = (animationCount % 20) / 20.0;
[myCircle setInteriorRed:1.0 green:green blue:1.0 alpha:1.0];
[myCircle setCurveRed:red green:1.0 blue:1.0 alpha:1.0];
[myCircle release];
}
|
If you know the C language and the Objective-C language then you can immediately see what is happening in the script. The first part, Declarations, defines the API that will be used and the second part, Execution Block, is what is executed when the script runs. Lets focus on the execution block. The following are the main points:
- First you make a Circle in the normal way by dragging it out, select the Program inspector editor, paste the script above into the program inspector text field and then click the Execute button. That associates the script with an existing circle and executes the script.
-
myCircle = [[Circle alloc] init];
assigns a circle object to the existing Circle.
-
[myCircle setInteriorRed:1.0 green:green blue:1.0 alpha:1.0];
sets the interior (fill) color of that circle.
-
[myCircle setCurveRed:red green:1.0 blue:1.0 alpha:1.0];
sets the curve (a.k.a.: border or stroke) color of that circle.
-
[myCircle release];
frees the circle object that you made.
- When you set Animation on then the script is repeatedly executed at regular time intervals. Each animation step increments the integer returned by
[myCircle animationCount];
and in that way, the colors of the circle are made dynamic.
- Remember to set the Execute During Animation Program state if you animate a graphic.
- It is important to declare all the methods and functions in the script before using them. That is because the script binds to a multi-typed system and the only way to resolve binding is via declaration.
At this point, you have been exposed to an overview of the way to program graphics. The rest of the programming sections deal with programming specifications.