Fun
use Carp;
use GD;
use WWPlot;
use Fun;
$fn = new Fun( rule_reference);
$fn = new Fun( rule_reference , graph_reference);
$fn = new Fun ( x_rule_ref, y_rule_ref );
$fn = new Fun ( x_rule_ref, y_rule_ref, graph_ref );
This module defines a parametric or non-parametric function object. The function object is designed to be inserted into a graph object defined by WWPlot.
The following functions are provided:
rule_reference is a reference to a subroutine which accepts a numerical value and returns a numerical value. The Fun object will draw the graph associated with this subroutine. For example: $rule = sub { my $x= shift; $x**2}; will produce a plot of the x squared. The new method returns a reference to the function object.
The function is also placed into the printing queue of the graph object pointed to by graph_reference and the domain of the function object is set to the domain of the graph.
A parametric function object is created where the subroutines refered to by x_rule_ref and y_rule_ref define the x and y outputs in terms of the input t.
This variant inserts the parametric function object into the graph object referred to by graph_ref. The domain of the function object is not adjusted. The domain's default value is (-1, 1).
All of the properties are set using the construction $new_value = $fn->property($new_value)
and read using $current_value = $fn->property()
The domain of the function is (tstart, tstop). steps is the number of subintervals used in graphing the function.
The color used to draw the function is specified by a word such as 'orange' or 'yellow'. $fn-
color('blue')> sets the drawing color to blue. The RGB values for the color are defined in the graph object in which the function is drawn. If the color, e.g. 'mauve', is not defined by the graph object then the function is drawn using the color 'default_color' which is always defined (and usually black).
A reference to the subroutine used to calculate the x value of the graph. This is set to the identity function (x = t ) when using the function object in non-parametric mode.
A reference to the subroutine used to calculate the y value of the graph.
The width in pixels of the pen used to draw the graph. The pen is square.
This defines a non-parametric function.
$fn->rule(sub {my $x =shift; $x**2;} )
is equivalent to
$fn->x_rule(sub {my $x = shift; $x;});
$fn->y_rule(sub {my $x = shift; $x**2;);
$fn->rule() returns the reference to the y_rule.
$array_ref = $fn->domain(-1,1) sets tstart to -1 and tstop to 1 and returns a reference to an array containing this pair of numbers.
$fn->draw($graph_ref) draws the function in the graph object pointed to by $graph_ref. If one of the points bounding a subinterval is undefined then that segment is not drawn. This usually does the "right thing" for functions which have simple singularities.
The graph object must respond to the methods below. The draw call is mainly for internal use by the graph object. Most users will not call it directly.
a hash containing the defined colors
a GD image object
draw line to the point (x,y) from the current position using the specified color. To obtain the color number use a construction such as $color_number = $graph_ref-
{colors}{'blue'};>
draw line to the point (x,y) using the pattern set by SetBrushed (see GD documentation)
set the current position to (x,y)