Table Of Contents
The following is a complete script for programming a Rectangle graphic. When animated, it makes the rectangle blink and move around in a circle. Remember to set the Execute During Animation Program state if you animate a graphic.
/* Declarations */
double cos(double a);
double sin(double a);
@@class() Rectangle: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)moveCenterToXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)sizeToCenteredWidth:(double)width height:(double)height;
@@method(public, instance) (void)release;
@@end
/* Execution block */
{
id myRectangle;
int ii;
unsigned animationCount;
double red, green;
double xValue, yValue;
myRectangle = [[Rectangle alloc] init];
animationCount = [myRectangle animationCount];
red = (animationCount % 10) / 10.0;
green = (animationCount % 20) / 20.0;
xValue = 250.0 + 100.0 * cos(animationCount/20.0);
yValue = 250.0 + 100.0 * sin(animationCount/20.0);
[myRectangle setInteriorRed:1.0 green:green blue:1.0 alpha:1.0];
[myRectangle setCurveRed:red green:1.0 blue:1.0 alpha:1.0];
[myRectangle moveCenterToXValue:xValue yValue:yValue];
[myRectangle release];
}
|
The general API is define in the section Graphic.