Table Of Contents

Graph IDEProgramming ► Function

The following is a complete script for programming a Function. It computes a cosine curve and then duplicates that curve five times using the recur method. The cosine is shifted up upon each recursion to demonstrate how to alter the data based upon recursion. Since it is often the case that a graph has multiple curves that are computed based upon data, the recur method is very important to the function graphic.

/* Declarations */

double cos(double a);

@@class() Function:Object

@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (unsigned)recursionCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
@@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)recur;
@@method(public, instance) (void)release;

@@end

/* Execution block */

{
id myFunction;
int ii;
double xValue, yValue;
unsigned animationCount;
unsigned recursionCount;
double red;

myFunction = [[Function alloc] init];

animationCount = [myFunction animationCount];
recursionCount = [myFunction recursionCount];

printf("animationCount: %d\n", animationCount);
printf("recursionCount: %d\n", recursionCount);

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

[myFunction emptyData];

for(ii = 0; ii < 500; ii++)
{
xValue = 0.01 * ii + animationCount * 0.5;
yValue = cos(xValue) + recursionCount;
[myFunction appendXValue:xValue yValue:yValue];
}

red = (animationCount % 10) / 10.0;

[myFunction setCurveRed:red green:0.0 blue:0.0 alpha:1.0];

if(recursionCount < 5)
{
[myFunction recur];
}

[myFunction release];

}

The general API is define in the section Graphic. The following is API description specific to the Function graphic.

@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
  Call like this:

[myFunction 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)appendMarkerRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
  Call like this:

[myFunction appendMarkerRed:0.5 green:0.4 blue:1.0 alpha:1.0];

That appends the marker color to the red, green, blue and alpha values of 0.5, 0.4, 1.0 and 1.0 respectively. Those values must be between 0.0 and 1.0. An alpha of 0.0 is transparent while 1.0 is completely opaque. Each argument must be a number literal or a variable (or expression) of type double. Note that this call must accompany a appendXValue:xValue yValue: call in order to synchronize the parameters that depend upon sequence index.

  @@method(public, instance) (void)appendSegmentRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
  Call like this:

[myFunction appendSegmentRed:0.5 green:0.4 blue:1.0 alpha:1.0];

That appends the segment color to the red, green, blue and alpha values of 0.5, 0.4, 1.0 and 1.0 respectively. Those values must be between 0.0 and 1.0. An alpha of 0.0 is transparent while 1.0 is completely opaque. Each argument must be a number literal or a variable (or expression) of type double. Note that this call must accompany a appendXValue:xValue yValue: call in order to synchronize the parameters that depend upon sequence index.

  @@method(public, instance) (void)appendBubbleValue:(double)aValue;
  Call like this:

[myFunction appendBubbleValue:aValue];

Appends aValue to the list of bubble values for the graphic. aValue must be of type double.

  @@method(public, instance) (void)sort;
  Call like this:

[myFunction sort];

Sorts the data points in x-order. You should attempt to append the data points in x-ascending order but if that is not possible then call this sort method after appending all data points. The points must be x-ascending.

  @@method(public, instance) (void)emptyData;
  Call like this:

[myFunction emptyData];

Removes (empties) all data from the graphic. Call this right before adding new data points.




© Copyright 1993-2022 by VVimaging, Inc. (VVI); All Rights Reserved. Please email support@vvi.com with any comments you have concerning this documentation. See Legal for trademark and legal information.