home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / apple / pcpigrfx.lbr / SINES.PZS / SINES.PAS
Encoding:
Pascal/Delphi Source File  |  1987-02-27  |  4.1 KB  |  124 lines

  1. PROGRAM sines; {demonstrates plot of sine function}
  2.  
  3. {Copyright 1984 by N.T.Carnevale.
  4.  Permission granted for nonprofit use.}
  5.  
  6. CONST
  7.   GRAFSCREEN=2; {use only hires screen 2 with PCPI v.2 CP/M}
  8.   BELL=7;
  9.  
  10. TYPE
  11.   {these are used to map the "real world" onto the display}
  12.   realdata=RECORD
  13.       x,y:real; {x&y world coordinates, that is, "real data"}
  14.     END;
  15.   screendata=RECORD
  16.       x,y:integer; {x&y display coordinates}
  17.     END;
  18.   realscalefactors=RECORD
  19.       mx,my,bx,by:real; {used to map world into display}
  20.     END;
  21.  
  22. {$I PCP.INC}
  23. {$I APLGR/G.INC}
  24. {$I APLGR/H.INC}
  25.  
  26. VAR
  27.   ans:char;
  28.   frameloc,framesize:screendata;
  29.   lowerleft,upperright:realdata;
  30.   frame:realscalefactors;
  31.   hue:hireshues;
  32.  
  33. {$I PLOTTER.INC}
  34. {PLOTTER.INC contains the following:
  35.  PROCEDURE setframe--sets up the coefficients ("magnifications"
  36.    and "shifts") that are used to transform or map "real data"
  37.    to the display.  Parameters are:
  38.      lowerleft,upperright:realdata--the opposite corners of
  39.        a rectangular area that contains the range of "real
  40.        data" to be plotted ("corners of the real world").
  41.      frameloc:screendata--left upper corner of area on the
  42.        screen where the data is to go (where to put the
  43.        picture).
  44.      framesize:screendata--dimensions of the area on the
  45.        screen where the data is to go (how big to make the
  46.        picture).
  47.      VAR frame:realscalefactors--this record contains the
  48.        coefficients (calculated by setframe) that will be
  49.        used by other procedures to map "real data" to the
  50.        display.
  51.  
  52.  PROCEDURE plot--draws a point on the hires page using
  53.    specified scale factors.  Parameters are:
  54.      point:realdata--x,y coordinates of the point in the
  55.        "real world."
  56.      frame:scalefactors--the coefficients used to map
  57.        the point onto the display.
  58.  
  59.  PROCEDURE plotline--starting from present cursor location,
  60.    draws a line to the point on the screen that corresponds
  61.    to a specified endpoint in the "real world," using
  62.    specified scale factors.  Parameters are:
  63.      endpoint:realdata--x,y coordinates of the end of the
  64.        line in the "real world."
  65.      frame:scalefactors--the coefficients used to map the
  66.        point onto the display.
  67. }
  68.  
  69.  
  70. PROCEDURE genplot;
  71. {generate and plot one cycle of a sine wave}
  72. CONST PI=3.1415926;
  73. VAR
  74.   i:integer;
  75.   point:realdata;
  76.   dx:real;
  77. BEGIN
  78.   point.x:=0.0;
  79.   dx:=0.02*pi;
  80.   point.y:=sin(point.x);
  81.   plot(point,frame);         {plot the first point}
  82.   FOR i:=1 TO 100 DO BEGIN
  83.     point.x:=point.x+dx;     {calculate the next point}
  84.     point.y:=sin(point.x);
  85.     plotline(point,frame);   {and draw a line to it}
  86.   END;
  87. END;
  88.  
  89. BEGIN
  90.   hirespatch;  {install register-loading routines}
  91.   writeln('Sine plotter');
  92.   write('First, screen ',GRAFSCREEN,
  93.         ' will be cleared--press return to proceed');
  94.   readln(ans);
  95.   hgrselect(GRAFSCREEN);           {select screen to use}
  96.   hiresgr(GRAFSCREEN,FULLSCREEN);  {  and clear it}
  97.   textscreen(1);                   {restore text display}
  98.   writeln;
  99.   writeln('Press return to plot sine function.');
  100.   writeln('After the bell rings, press return again');
  101.   writeln('  to leave graphics mode.');
  102.   readln(ans);
  103.   {specify limits of "real world" data}
  104.   lowerleft.x:=0.0;    lowerleft.y:=-1.0;
  105.   upperright.x:=2*PI;  upperright.y:=1.0;
  106.   {set up size of display area}
  107.   framesize.x:=HIHRES - 90;  framesize.y:=HIVRES DIV 2;
  108.   {put first frame at top left-hand corner of display}
  109.   frameloc.x:=0;  frameloc.y:=0;
  110.   hiresgr(GRAFSCREEN,FULLSCREEN);  {go back to graphics}
  111.   hue:=BLACK1;                     {first "color" to use}
  112.   REPEAT
  113.     hue:=succ(hue);             {advance to the next color}
  114.     hisetcolor(hue);
  115.     frameloc.y:=frameloc.y+10;  {  and shift the frame}
  116.     frameloc.x:=frameloc.x+12;
  117.     setframe(lowerleft,upperright,frameloc,framesize,frame);
  118.     genplot;                    {plot one sine wave}
  119.   UNTIL hue=WHITE2;
  120.   writeln(chr(BELL));  {ring the bell}
  121.   readln(ans);         {wait until return key is pressed}
  122.   textscreen(1);       {restore text display before exit!}
  123. END.  {end of PROGRAM sines}
  124.