Table Of Contents
The following is a complete script for programming a Polygon graphic. It computes a somewhat circular distribution of points.
/* Declarations */
double cos(double a);
double sin(double a);
@@class() Polygon:Object
@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)release;
@@end
/* Execution block */
{
id myPolygon;
int ii;
double xValue, yValue;
unsigned animationCount;
myPolygon = [[Polygon alloc] init];
animationCount = [myPolygon animationCount];
printf("animationCount: %d\n", animationCount);
/*
Empty the data and then append new data.
*/
[myPolygon emptyData];
for(ii = 0; ii < 20; ii++)
{
red = (animationCount % 10) / 10.0;
green = (animationCount % 30) / 30.0;
blue = (ii % 20) / 20.0;
xValue = cos(ii * .02) + red * sin(ii * .01);
yValue = sin(ii * .02);
[myPolygon appendXValue:xValue yValue:yValue];
}
[myPolygon release];
}
|
The general API is define in the section Graphic. The following is API description specific to the Polygon graphic.
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
|
|
Call like this:
[myPolygon appendXValue:xValue yValue:yValue];
Appends the x and y values to the list of data points for the graphic. The x and y values forms a 2D point. Each value must be of type double.
|
@@method(public, instance) (void)emptyData;
|
|
Call like this:
[myPolygon emptyData];
Removes (empties) all data from the graphic. Call this right before adding new data points.
|