/*
This is an example script for a 2D trajectory graphic. Click the Execute button to apply and then execute this script. Upon each execution the trajectory alters its appearance. Turn on animation to execute periodically. Note that typically a trajectory graphic should be instantiated on a graph data layer and the graph should be set to autoscale during animation.
*/

/* Declarations */

double cos(double a);
double sin(double a);

@@class() Trajectory:Object

@@method(public, class) (id)stored;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)appendBubbleValue:(double)aValue;
@@method(public, instance) (void)appendSegmentRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;

@@end

/* Execution block */

{
id myTrajectory;
int ii;
double xValue, yValue, radius, center, phase;
unsigned animationCount;
double red, green, blue;

myTrajectory = [Trajectory stored];

animationCount = [myTrajectory animationCount];

/*
Empty the data and then append new data.
*/

[myTrajectory emptyData];

center = 4.0;
phase = animationCount * 0.1;

for(ii = 0; ii < 40; ii++)
{

radius = ii * 0.1;

red = 1.0;
green = (animationCount % 30) / 30.0;
blue = 1.0;
xValue = radius * cos(ii * .3 + phase) + center;
yValue = radius * sin(ii * .3 + phase) + center;

[myTrajectory appendXValue:xValue yValue:yValue];
[myTrajectory appendSegmentRed:red green:0.0 blue:blue alpha:1.0];
}

}
