home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / WILGRAPH.ZIP / WILGRAPH.PAS
Encoding:
Pascal/Delphi Source File  |  1989-08-09  |  5.1 KB  |  172 lines

  1.  
  2. {WILGRAPH }
  3. {Tools for graphics use.  Authored by Jack M. Wilson for Project M.U.P.P.E.T.}
  4. {                        University of Maryland                              }
  5. {                      (301) 454-5327 or 345-4200                            }
  6. {                                                                            }
  7. {Includes:   Reverse_Video; Blink_Video, Reg_Video                           }
  8. {            Print (x,y,attribute: integer; FieldID: BigStr)                 }
  9. {            ViewPort(VNum,VPX1,VPY1,VPX2,VPY2, VPcolor: integer)            }
  10. {            Scale(Snum :integer; sXmin,sYmin,sXmax,sYmax :real)             }
  11. {            PlotLine(Vnum,Snum:integer; Rx1,Ry1,Rx2,Ry2:real;pcolor:integer)}
  12. {            PlotData(D:DataType; NumData,Vnum, Snum, pcolor:integer)        }
  13. {            PlotDataPoints(D:DataType; NumData,Vnum, Snum, pcolor:integer)  }
  14. {            Axis(Vnum,Snum:integer;Xint,Yint,TicX,TicY:real;Pcolor:integer) }
  15.  
  16. Const
  17.      Pi = 3.14159265;
  18. Type
  19.      BigStr = String[80];
  20.      DataType = Array[0..200,1..2] of Real;
  21.      DataGrType = Array[0..200,1..2] of Integer;
  22.      View = record
  23.             Vx1,Vy1,Vx2,Vy2,Vcolor: Integer;
  24.             end;
  25.      GraphScale = record
  26.             Xmin,Ymin,Xmax,Ymax: real;
  27.             end;
  28. Var
  29.      Data        : DataType;
  30.      Views       : Array[1..5] of View;
  31.      GraphScales : Array[1..5] of GraphScale;
  32.  
  33. Procedure Reverse_Video;
  34.     Begin
  35.     TextColor(White); TextBackground(Black);
  36.     end;
  37. Procedure Blink_Video;
  38.     Begin
  39.     TextColor(Black+Blink); TextBackground(White);
  40.     end;
  41. Procedure Reg_Video;
  42.     Begin
  43.     TextColor(White); TextBackground(Blue);
  44.     end;
  45.  
  46. Procedure Print (x,y,attribute: integer; FieldID: BigStr);
  47.   {Attribute = 1 is reverse and 0 is regular}
  48.   Begin
  49.     If x<0 then x:=(80 - Length(FieldID)) div 2;
  50.     If y<0 then y:= 12;
  51.     If (x>80) or (y>25) then writeln('Error in Print format');
  52.     If Attribute=1  then Reverse_Video;
  53.     Gotoxy(x,y); Write(FieldID);
  54.     Reg_Video;
  55.     end;
  56.  
  57.  
  58.  Procedure ViewPort(VNum,VPX1,VPY1,VPX2,VPY2, VPcolor: integer);
  59.  
  60.      begin
  61.        with Views[Vnum] do begin
  62.           Vx1:=VPX1;
  63.           Vy1:=VPY1;
  64.           Vx2:=VPX2;
  65.           Vy2:=VPY2;
  66.           Vcolor:=VPcolor;
  67.           end;
  68.      end;
  69.  
  70. Procedure Scale(Snum :integer; sXmin,sYmin,sXmax,sYmax :real);
  71.      begin
  72.         with GraphScales[Snum] do begin
  73.           Xmin:=sXmin;
  74.           Ymin:=sYmin;
  75.           Xmax:=sXmax;
  76.           Ymax:=sYmax;
  77.           end;
  78.      end;
  79.  
  80. Procedure PlotLine(Vnum,Snum:integer; Rx1,Ry1,Rx2,Ry2:real;pcolor:integer);
  81. var
  82.     Gx1, Gy1, Gx2, Gy2: integer;
  83.  
  84.     begin
  85.       With Views[vnum] do begin
  86.       With GraphScales[snum] do begin
  87.         GraphWindow(Vx1,Vy1,Vx2,Vy2);
  88.            Gx1:=Round((Vx2-Vx1)*(Rx1 -Xmin)/(xmax-xmin));
  89.            Gy1:=Round((Vy2-Vy1)*(Ymax -Ry1)/(ymax-ymin));
  90.            Gx2:=Round((Vx2-Vx1)*(Rx2 -Xmin)/(xmax-xmin));
  91.            Gy2:=Round((Vy2-Vy1)*(Ymax -Ry2)/(ymax-ymin));
  92.         Draw(Gx1,Gy1,Gx2,Gy2,pcolor);
  93.       end;
  94.       end;
  95.     end;
  96.  
  97. Procedure PlotData(D:DataType; NumData,Vnum, Snum, pcolor:integer);
  98.  
  99. var
  100.      Rx1,Ry1,Rx2,Ry2     : Real;
  101.      DataGr              : DataGrType;
  102.      I                   : Integer;
  103.      begin
  104.        With Views[vnum] do begin
  105.        With GraphScales[snum] do begin
  106.            GraphWindow(Vx1,Vy1,Vx2,Vy2);
  107.            FillScreen(Vcolor);
  108.               Rx1:=D[0,1];
  109.               Ry1:=D[0,2];
  110.            For I:=1 to NumData do begin
  111.               Rx2:=D[I,1];
  112.               Ry2:=D[I,2];
  113.               PlotLine(Vnum,Snum,Rx1,Ry1,Rx2,Ry2,pcolor);
  114.               Rx1:=Rx2;  Ry1:=Ry2;
  115.               end;
  116.  
  117.         end;
  118.         end;
  119.      end;
  120.  
  121. Procedure PlotDataPoints(D:DataType; NumData,Vnum, Snum, pcolor:integer);
  122.  
  123. var
  124.      I,Gx,Gy              : Integer;
  125.  
  126.      begin
  127.        With Views[vnum] do begin
  128.        With GraphScales[snum] do begin
  129.            GraphWindow(Vx1,Vy1,Vx2,Vy2);
  130.            FillScreen(Vcolor);
  131.            For I:=1 to NumData do begin
  132.               Gx:=Round((Vx2-Vx1)*(D[I,1] -Xmin)/(xmax-xmin));
  133.               Gy:=Round((Vy2-Vy1)*(Ymax -D[I,2])/(ymax-ymin));
  134.               Plot(Gx,Gy,pcolor);
  135.               end;
  136.  
  137.         end;
  138.         end;
  139.      end;
  140.  
  141.  
  142. Procedure Axis(Vnum,Snum:integer;Xint,Yint,TicX,TicY:real;Pcolor:integer);
  143.  
  144. var
  145.   x,y:real;
  146.  
  147.      begin
  148.        With Views[vnum] do begin
  149.         With GraphScales[snum] do begin
  150.           Plotline(Vnum,Snum,xmin,yint,xmax,yint,pcolor);
  151.           Plotline(Vnum,Snum,xint,ymin,xint,ymax,pcolor);
  152.           If TicX >0 then begin
  153.             X:=Xmin;
  154.             While X<Xmax do begin
  155.                PlotLine(Vnum,Snum,X,Yint,X,Yint+0.01*(Ymax-Ymin),Pcolor);
  156.                X:=X+TicX;
  157.             end;
  158.           end;
  159.           If TicY >0 then begin
  160.             Y:=Ymin;
  161.             While Y<Ymax do begin
  162.                PlotLine(Vnum,Snum,Xint,Y,Xint+0.01*(Xmax-Xmin),Y,Pcolor);
  163.                Y:=Y+TicY;
  164.             end;
  165.           end;
  166.  
  167.         end;
  168.        end;
  169.      end;
  170.  
  171.  
  172.