dos_compilers/Borland Turbo Pascal v55/FIGDEMO.PAS
2024-07-02 06:49:04 -07:00

94 lines
2.6 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ Copyright (c) 1989 by Borland Interational, Inc. }
program FigureDemo;
{ From P-47 of the Object-Oriented Programming Guide.
Extending FIGURES.PAS with type Arc.
}
uses Crt, DOS, Graph, Figures;
type
Arc = object (Circle)
StartAngle, EndAngle : Integer;
constructor Init(InitX, InitY : Integer;
InitRadius : Integer;
InitStartAngle, InitEndAngle : Integer);
procedure Show; virtual;
procedure Hide; virtual;
end;
var
GraphDriver : Integer;
GraphMode : Integer;
ErrorCode : Integer;
AnArc : Arc;
ACircle : Circle;
{--------------------------------------------------------}
{ Arc's method declarations: }
{--------------------------------------------------------}
constructor Arc.Init(InitX,InitY : Integer;
InitRadius : Integer;
InitStartAngle, InitEndAngle : Integer);
begin
Circle.Init(InitX, InitY, InitRadius);
StartAngle := InitStartAngle;
EndAngle := InitEndAngle;
end;
procedure Arc.Show;
begin
Visible := True;
Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
end;
procedure Arc.Hide;
var
TempColor : Word;
begin
TempColor := Graph.GetColor;
Graph.SetColor(GetBkColor);
Visible := False;
{ Draw the arc in the background color to hide it }
Graph.Arc(X, Y, StartAngle, EndAngle, Radius);
SetColor(TempColor);
end;
{--------------------------------------------------------}
{ Main program: }
{--------------------------------------------------------}
begin
GraphDriver := Detect; { Let the BGI determine what board
you're using }
DetectGraph(GraphDriver, GraphMode);
InitGraph(GraphDriver, GraphMode,'');
if GraphResult <> GrOK then
begin
WriteLn('>>Halted on graphics error:',
GraphErrorMsg(GraphDriver));
Halt(1)
end;
{ All descendents of type Point contain virtual methods and }
{ *must* be initialized before use through a constructor call. }
ACircle.Init(151, 82, { Initial X,Y at 151,82 }
50); { Initial radius of 50 pixels }
AnArc.Init(151, 82, { Initial X,Y at 151,82 }
25, 0, 90); { Initial radius of 50 pixels }
{ Start angle: 0; End angle: 90 }
{ Replace AnArc with ACircle to drag a circle instead of an }
{ arc. Press Enter to stop dragging and end the program. }
ACircle.Drag(5); { Parameter is # of pixels to drag by }
CloseGraph;
RestoreCRTMode;
end.