home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 4.ddi / DOCDEMOS.ZIP / FIGDEMO.PAS next >
Encoding:
Pascal/Delphi Source File  |  1990-10-23  |  3.6 KB  |  119 lines

  1.  
  2. { Copyright (c) 1989,90 by Borland International }
  3.  
  4. program FigureDemo;
  5. { From Chapter 4 the Turbo Pascal 6.0 User's Guide.
  6.   Extending FIGURES.PAS with type Arc.
  7.  
  8.   If you are running this program in the IDE, be sure to enable
  9.   the full graphics save option when you load TURBO.EXE:
  10.  
  11.     turbo -g
  12.  
  13.   This ensures that the IDE fully swaps video RAM and keeps
  14.   "dustclouds" from appearing on the user screen when in
  15.   graphics mode. You can enable this option permanently
  16.   via the Options|Environment|Startup dialog.
  17.  
  18.   This program uses the Graph unit and its .BGI driver files to
  19.   display graphics on your system. The "PathToDrivers"
  20.   constant defined below is set to \TP\BGI, which is the default
  21.   location of the BGI files as installed by the INSTALL program.
  22.   If you have installed these files in a different location, make
  23.   sure the .BGI file for your system (EGAVGA.BGI, etc.) is in the
  24.   current directory or modify the "PathToDrivers" constant
  25.   accordingly.
  26. }
  27.  
  28. uses Crt, DOS, Graph, Figures;
  29.  
  30. const
  31.   PathToDrivers = '\TP\BGI';  { Default location of *.BGI files }
  32.  
  33. type
  34.   Arc = object (Circle)
  35.     StartAngle, EndAngle : Integer;
  36.     constructor Init(InitX, InitY: Integer; InitRadius: Integer;
  37.       InitStartAngle, InitEndAngle: Integer);
  38.     procedure Show; virtual;
  39.     procedure Hide; virtual;
  40.   end;
  41.  
  42. var
  43.   GraphDriver: Integer;
  44.   GraphMode: Integer;
  45.   ErrorCode: Integer;
  46.   AnArc: Arc;
  47.   ACircle: Circle;
  48.  
  49.  
  50. {--------------------------------------------------------}
  51. { Arc's method declarations:                             }
  52. {--------------------------------------------------------}
  53.  
  54. constructor Arc.Init(InitX,InitY: Integer; InitRadius: Integer;
  55.   InitStartAngle, InitEndAngle: Integer);
  56. begin
  57.   Circle.Init(InitX, InitY, InitRadius);
  58.   StartAngle := InitStartAngle;
  59.   EndAngle   := InitEndAngle;
  60. end;
  61.  
  62. procedure Arc.Show;
  63. begin
  64.   Visible := True;
  65.   Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
  66. end;
  67.  
  68. procedure Arc.Hide;
  69. var
  70.   TempColor: Word;
  71. begin
  72.   TempColor := Graph.GetColor;
  73.   Graph.SetColor(GetBkColor);
  74.   Visible := False;
  75.   { Draw the arc in the background color to hide it }
  76.   Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
  77.   SetColor(TempColor);
  78. end;
  79.  
  80.  
  81. {--------------------------------------------------------}
  82. { Main program:                                          }
  83. {--------------------------------------------------------}
  84.  
  85. begin
  86.   GraphDriver := Detect; { Let BGI determine which board you're using }
  87.   DetectGraph(GraphDriver, GraphMode);
  88.   InitGraph(GraphDriver, GraphMode, PathToDrivers);
  89.   if GraphResult <> GrOK then
  90.   begin
  91.     Writeln(GraphErrorMsg(GraphDriver));
  92.     if GraphDriver = grFileNotFound then
  93.     begin
  94.       Writeln('in ', PathToDrivers,
  95.         '. Modify this program''s "PathToDrivers"');
  96.       Writeln('constant to specify the actual location of this file.');
  97.       Writeln;
  98.     end;
  99.     Writeln('Press Enter...');
  100.     Readln;
  101.     Halt(1);
  102.   end;
  103.  
  104. { All descendents of type Point contain virtual methods and    }
  105. { *must* be initialized before use through a constructor call. }
  106.  
  107.   ACircle.Init(151, 82,      { Initial X,Y at 151,82 }
  108.                50);          { Initial radius of 50 pixels }
  109.   AnArc.Init(151, 82,        { Initial X,Y at 151,82 }
  110.              25, 0, 90);     { Initial radius of 50 pixels }
  111.                              { Start angle: 0; End angle: 90 }
  112.  
  113. { Replace AnArc with ACircle to drag a circle instead of an }
  114. { arc. Press Enter to stop dragging and end the program.   }
  115.  
  116.   ACircle.Drag(5);       { Parameter is # of pixels to drag by }
  117.   CloseGraph;
  118. end.
  119.