/////////////////////////////////////////////////////////// // gwiz.cpp Demo program /////////////////////////////////////////////////////////// /* A small program used for mathematical tasks one would need to perform computations and plot graphs. A set of basic display and graphics functions are declared and defined in gwiz.h, which is *not* a true header file. The computations are in the function num(), and graphs are in the function plot(), here below. These two functions can easily be modified to perform similar new tasks which may be needed. Copy or rename this file as you please, say to ap1.cpp Re choose the prog name immediately below this comment. Add some inline functions in the variables and functions area. Rewrite num() and plot() to suit your application. The include files gwiz.h and gwiz.rc need not be changed at all. Typically one would start a new Win32 project, add the files {gwiz.h, gwiz.rc, ap1.cpp}, build, and run. Thus, by writing only the single short new file ap1.cpp, and including the files {gwiz.h, gwiz.rc}, one immediately obtains a working graphics program. Richard Hall */ // ------------------------------------------ // program name extern const char prog[] = "MyFirstAp" ; // ------------------------------------------ // help string extern const char helpstr[] = "gwiz v(0.9) \n\n\ Num Text\n\n\ Plot Graphics\n\n\ (c) Richard Hall October 2002"; // ------------------------------------------------------------- #include "gwiz.h" #include "gwiz.rc" // ------------------------------------------------------ // variables and functions needed for this program // ------------------------------------------------------ inline double g(double x) // test functions for gwin::xplot { return exp(-x*x); } char gstr[80] = "g(x) = exp(-x^2)"; inline double gm(double x) { return -exp(-x*x); } inline double f(double x) { return g(x)*cos(15*x); } // ------------------------------------------------ // class for fun pointer test function class fufun : public fun { public: inline fufun() {} inline ~fufun() {} inline double f(double x) { return 0.8/(1+x*x); } }; // ---------------------------------------------------------- // The definitions of num() and plot() declared in gwiz.h // ---------------------------------------------------------- void num(gwin &w, int p) { w.open(p); w.locate(10,90,10,90); w.preframe(); w.scale(0,10,10,0,100); w.p(1,1,"Hello World"); w.p(1,2,"This is my first program"); w.p(1,3,gstr); double x = 1, y = g(x); w.pf(1,4,"g(%.6f) = %.6f",x,y); w.close(); } // ------------------------------------------------ void plot(gwin &w, int p) { w.open(p); int wb = 20; // screen window bottom if (p == 1) wb = 40; // higher for printer w.locate(20,80,wb,80); // graph window (%) w.clip(); // clip to window vertically w.preframe(); w.scale(-4,4,-1.2,1.2,500); // axes w.move(-3,0); w.line(3,0); w.move(0,-1.2); w.line(0,1.2); // plot fptype1 (top-level) functions w.xplot(g); w.xplot(gm); w.xplot(f); // label graph double x,y,d; x = 0.6; y = g(x); d = 0.12; w.move(x,y); w.line(x+d,y+d); w.pf(x+d,y+2*d,"g(%.6g) = %.6g",x,y); // add title outside window w.scale(0,100,0,100,10); w.unclip(); w.p(5,110,"Wave Packet plus"); w.clip(); // new little window for fu wb = 60; if (p == 1) wb = 65; w.locate(22,40,wb,78); w.preframe(); w.clip(); w.scale(-5,5,0,1,200); // create and plot a fun pointer fu fufun *fu = new fufun(); w.xplot(fu); // label fu x = 0.6; y = g(x); d = 0.12; w.move(x,y); w.line(x+d,y+d); w.p(x+d,y+2*d,"fu"); // delete fu delete fu; w.close(); } // ---------------------------------------------