For example, the following script creates an interactive sine wave graph. The script automates the interaction by sending messages to the frame box inside the window. Note the frame box assignment to tf in the middle of the script).
amplitude = 1;
freq = 1;
phase = 0;
win = New Window( "Wiggle Wave",
Graph Box(
Frame Size( 500, 300 ),
X Scale( -5, 5 ),
Y Scale( -5, 5 ),
Y Function( amplitude * Sine( x / freq + phase ), x );
Handle(
phase,
amplitude,
/* current values of phase and amplitude position the square handle.
script begins after the last comma after amplitude */
phase = x;
amplitude = y;
/* x and y have been set to the handle’s position
but the handle doesn’t move unless the values specified
in the first two arguments are updated */
);
Handle( freq, .5, freq = x );
// Handle works similarly except that the y value is .5
Text( // display a text string in the graph
{3, 4},
"amplitude: ",
Round( amplitude, 4 ), // display the current value
{3, 3.5},
"frequency: ",
Round( freq, 4 ), // display the current value
{3, 3},
"phase: ",
Round( phase, 4 ) // display the current value
);
)
);
tf = win[Frame Box( 1 )]; // get the frame box (the graph)
For( amplitude = -4, amplitude < 4, amplitude += .1,// animate the amplitude
tf << Reshow // force the graph to update
);
amplitude = 1; // use for loops for more complex movement
freq = 1;
phase = 0;
For( i = 0, i < 1000, i++,
amplitude += (Random Uniform() - .5);
amplitude = If(
amplitude > 4, 4,
amplitude < -4, -4,
amplitude
);
freq += (Random Uniform() - .5) / 20;
phase += (Random Uniform() - .5) / 10;
tf << Reshow;
Wait( .05 );
);