coding UTF-8; import Math; import Text; import GUI; import File; import tool.Graph2D; /** The default value of the expression x(t) to plot graph */ const string DEFAULT_X_EXPRESSION = "cos(5*t)"; /** The default value of the expression y(t) to plot graph */ const string DEFAULT_Y_EXPRESSION = "sin(10*t)"; /** The default value of the maximum value of the parameter variable t. */ const string DEFAULT_T_MAX = "1.0"; /** The default value of the minimum value of the parameter variable t. */ const string DEFAULT_T_MIN = "-1.0"; /** The default value of the number of the point of the graph. */ const string DEFAULT_T_N = "300"; // Followings are variables to store IDs of the graph and GUI components. /** Stores the ID of the graph. */ int graph = NULL; /** Stores the ID of the input-window. */ int window = NULL; /** Stores the ID of the text-field of the expression of x(t). */ int xExpressionField = NULL; /** Stores the ID of the text-field of the expression of y(t). */ int yExpressionField = NULL; /** Stores the ID of the text-field of the maximum value of the parameter variable t. */ int tMaxField; /** Stores the ID of the text-field of the minimum value of the parameter variable t. */ int tMinField; /** Stores the ID of the text-field of the number of points of the graph. */ int tNField; /** Stores the ID of the PLOT button. */ int plotButton; /** Stores the ID of the CLEAR button. */ int clearButton; /** Stores the ID of the ANIMATION button. */ int animationButton; /** Stores the ID of the EXPORT button. */ int exportButton; /** Stores the ID of the EXIT button. */ int exitButton; /** * Invoked automatically when this program have started. */ void main(){ // Set the console window invisible because it is not necessary for GUI program. hide(); // Create (or get from the system) a 2D graph window. graph = getGraph2D(); // Set the size and the location of the graph-window. setGraph2DLocation(graph, 330, 0); setGraph2DSize(graph, 720, 600); // Create and launch the input-window. createInputWindow(); // If you want to read processings after when the user click PLOT button, // see "onButtonClick" function at near the bottom of this code. } /** * Plots the expression to the 2D graph. * * @param xExpression The expression of x(t). * @param yExpression The expression of y(t). * @param tMin The minimum value of the parameter variable t. * @param tMax The maximum value of the parameter variable t. * @param n The number of points of the graph. */ void plotGraph( string xExpression, string yExpression, double tMax, double tMin, int n ){ // Arrays storing vertices data to transfer the graph. double xArray[n]; double yArray[n]; // Coordinate variables of a point. double x; double y; double t; // Check the syntax of the expression x(t) and y(t). if( !evaluable(xExpression, 0.0) ){ alert("The form of the expression of \"x(t)\" is wrong."); return; } if( !evaluable(yExpression, 0.0) ){ alert("The form of the expression of \"y(t)\" is wrong."); return; } // Evaluate coordinate values (x,y) with n-1 equally divided values of between t-max and t-min, // and store them to arrays. float dt = (tMax-tMin)/(n-1); for( int i=0; i