home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / DEMO / SRC / BARDEMO.MOD next >
Text File  |  1996-11-10  |  6KB  |  174 lines

  1. MODULE BarDemo;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*              Test of module WGraph                   *)
  6.         (*              Draws some bar graphs                   *)
  7.         (*                                                      *)
  8.         (*  Programmer:         S.P. Lontis, P. Moylan.         *)
  9.         (*  Last edited:        11 November 1996                *)
  10.         (*  Status:             Working                         *)
  11.         (*                                                      *)
  12.         (*      This is a copy of the Lontis version,           *)
  13.         (*      which I'm gradually modifying.                  *)
  14.         (*                                                      *)
  15.         (*      See comments inside the code.  This is          *)
  16.         (*      basically working, but I'm still fiddling with  *)
  17.         (*      the details.                                    *)
  18.         (*                                                      *)
  19.         (********************************************************)
  20.  
  21. FROM Graphics IMPORT
  22.     (* proc *)  GetScreenShape;
  23.  
  24. FROM GWindows IMPORT
  25.     (* type *)  Window, BorderType,
  26.     (* proc *)  InitGraphics, WriteString, WriteLn, GString, GStringUp,
  27.                 OpenWindow, CloseWindow, ClearWindow;
  28.  
  29. FROM WGraph IMPORT
  30.     (* type *)  Graph, BarType, GraphType, LineType, MarkType,
  31.     (* proc *)  OpenGraph, DrawXAxis, DrawAxes, BarGraph;
  32.  
  33. FROM MATHLIB IMPORT
  34.     (* proc *)  Sin, Cos, Log;
  35.  
  36. FROM Keyboard IMPORT
  37.     (* proc *)  InKey;
  38.  
  39. FROM Timer IMPORT
  40.     (* proc *)  Sleep;
  41.  
  42. (************************************************************************)
  43.  
  44. PROCEDURE Pause;
  45.  
  46.     BEGIN
  47.         Sleep (2000);
  48.         (* dummy := InKey(); *)
  49.     END Pause;
  50.  
  51. (************************************************************************)
  52.  
  53. PROCEDURE RunTheDemo;
  54.  
  55.     VAR G1, G2, G3, G4, G5, G6: Graph;
  56.         i : [0..4];
  57.         w1, comments, w3: Window;
  58.         x, y, z, t: ARRAY [0..4] OF LONGREAL;
  59.         Xmax, Ymax, maxcolour, CharHeight: CARDINAL;
  60.         barwidth: LONGREAL;
  61.         ibw: CARDINAL;
  62.  
  63.     BEGIN
  64.         GetScreenShape (Xmax, Ymax, maxcolour, CharHeight);
  65.  
  66.         (* Set up the demonstration data arrays.        *)
  67.  
  68.         FOR i := 0 TO 4 DO
  69.             y[i] := -5.0*Sin(6.24*VAL(LONGREAL,i))+1.0;
  70.             x[i] := 5.0*Cos(6.24*VAL(LONGREAL,i))+0.5;
  71.             t[i] := x[i] + VAL(LONGREAL,i)*0.6;
  72.             z[i] := 0.5*VAL(LONGREAL,i) + 1.0;
  73.         END (* FOR *);
  74.  
  75.         (* Opening comments *)
  76.  
  77.         OpenWindow (comments, 0, 0, Xmax, Ymax DIV 4 - 1, 0, 2, double);
  78.         WriteString (comments,'The Graph application also draws bar charts');
  79.         WriteLn(comments);
  80.         WriteString (comments, '   for example:'); WriteLn(comments);
  81.         WriteString (comments, '           Simple bar graphs');
  82.         Pause;
  83.  
  84.         (* A simple bar graph - G1 in w1.       *)
  85.  
  86.         OpenWindow (w1, 0, Ymax DIV 4, Xmax, Ymax, 7, 6, single);
  87.         barwidth := VAL(LONGREAL,Xmax-180)/25.0;
  88.         OpenGraph (G1,w1,bar,joined,100,30,Xmax-80,3*Ymax DIV 4 - 20,
  89.                                 barwidth,0.0,4.0*barwidth,10.0,none);
  90.         DrawAxes (G1, 0.0, 0, 2, TRUE, 1.0, 0, 2, TRUE);
  91.         BarGraph (G1, y, 5, One);
  92.  
  93.         Pause;
  94.  
  95.         (* Graph G6 in w3 is another bar graph. *)
  96.  
  97.         OpenWindow (w3, Xmax DIV 2, Ymax DIV 2, Xmax, Ymax, 1, 3, double);
  98.         OpenGraph (G6,w3,bar,joined,50,40,Xmax DIV 2 - 30,Ymax DIV 2 - 20,
  99.                                 10.0,0.0,30.0,10.0,none);
  100.         DrawAxes (G6, 0.0, 0, 2, TRUE, 1.0, 0, 2, TRUE);
  101.         BarGraph (G6,z,5,One);
  102.  
  103.         Pause;
  104.  
  105.         WriteString (comments,' - to which you can add labelling');
  106.         WriteLn(comments);
  107.         Pause;
  108.  
  109.         (* Add some text to G1. *)
  110.  
  111.         GStringUp (w1, 20, 3*Ymax DIV 8 - 70, 'RainFall * 100 mm');
  112.         GString (w1, Xmax DIV 2, 5, 'Months');
  113.         GString (w1, Xmax DIV 2 -100, 3*Ymax DIV 4 - 50,
  114.                                 'GRAPH OF MONTHLY RAINFALL');
  115.         Pause;
  116.  
  117.         (* And then some text to G6.    *)
  118.  
  119.         GStringUp (w3, 20, Ymax DIV 4, 'Population');
  120.         GString (w3, Xmax DIV 4, 5, 'Time in Days.');
  121.         Pause;
  122.  
  123.         (* G2 is a copy of G1, in the same window, but with different   *)
  124.         (* scale and bar pattern.                                       *)
  125.  
  126.         WriteString (comments, "           Here's a similar graph, with a different scale for the Y axis");
  127.         WriteLn(comments);
  128.         Pause;
  129.         ibw := VAL(CARDINAL,barwidth);
  130.         OpenGraph(G2,w1,bar,joined,100+ibw,30,Xmax-80,3*Ymax DIV 4 - 20,
  131.                                 barwidth,0.0,4.0*barwidth,2.0,none);
  132.         DrawAxes (G2, 0.0, 0, 2, TRUE, 0.25, 45, 2, TRUE);
  133.         BarGraph (G2,y,5,Two);
  134.         Pause;
  135.  
  136.         (*  G3, G4, and G5 are plotted on the same axes as G1   *)
  137.  
  138.         OpenGraph(G3,w1,bar,joined,100+2*ibw,30,Xmax-80,3*Ymax DIV 4 - 20,
  139.                                 barwidth,0.0,4.0*barwidth,10.0,none);
  140.         WriteString (comments, '           Extra Bars can be added to the existing graph.');
  141.         WriteLn(comments);
  142.         Pause;
  143.         DrawXAxis (G3, 0.0, 0, 2, TRUE);
  144.         BarGraph (G3,x,5,Three);
  145.         Pause;
  146.  
  147.         OpenGraph(G4,w1,bar,joined,100+3*ibw,30,Xmax-80,3*Ymax DIV 4 - 20,
  148.                                         barwidth,0.0,4.0*barwidth,10.0,none);
  149.         OpenGraph (G5,w1,bar,joined,100+4*ibw,30,Xmax-80,3*Ymax DIV 4 - 20,
  150.                                         barwidth,0.0,4.0*barwidth,10.0,none);
  151.  
  152.         WriteString (comments, '           With five different types of bar patterns.');
  153.         WriteLn(comments);
  154.         Pause;
  155.  
  156.         DrawXAxis (G4, 0.0, 0, 2, TRUE);
  157.         BarGraph(G4,t,5,Four);
  158.         DrawXAxis (G5, 0.0, 0, 2, TRUE);
  159.         BarGraph(G5,z,5,Five);
  160.         Pause;
  161.         CloseWindow(w1);  Pause;
  162.         CloseWindow(w3);  Pause;
  163.         CloseWindow(comments);
  164.  
  165.     END RunTheDemo;
  166.  
  167. (************************************************************************)
  168.  
  169. BEGIN
  170.     InitGraphics (18);
  171.     RunTheDemo;
  172. END BarDemo.
  173.  
  174.