.


:




:

































 

 

 

 





. . , () , , () .

, , . 16 , , (. 13). . , , , .

. .

,

. , , , . , , . . T , , . , , . , , , .

, (, , , ..), TPU- , . , , . , , , .

, (, , , ) . [6].

TGraphObject, , :

 

Type

TGraphObj = Object

x, y: Integer; color: Word;

constructor init(ax, ay: Integer; acolor: Word);

procedure Draw(acolor: Word); Virtual;

procedure Show;

procedure Hide;

procedure Moveto(dx, dy: Integer);

end;

 

: x, y ; Color . . TGraphObj, , , . ( x y) ( Color). Draw , Show Hide . MoveTo . , TGraphObj, . .

, . Init TGraphObj .

Draw . TGraphObj ‑. PutPixel, Line .. TGraphObj Draw (). TGraphObj , , , TGraphObj Draw, .

TGraphObj Draw. Init Draw.

TGraphObj Draw . Show, Draw aColor, Color, , Hide Draw c GetBkColor, .. .

TGraphObj , MoveTo. Hide o , Show . Show, Hide Draw. MoveTo , Draw.

, , .. . , .

 

:

 

Constructor TGraphobj.init;

Begin x:= ax; y:= ay; color:= acolor; end;

 

, .. . .

TGraphObj , Draw .

 

Procedure TGraphObj.draw;

Begin End;

 

Hide, Show MoveTo , Draw .

 

Procedure TGraphObj.Show;

Begin Draw(color); End;

Procedure TGraphObj.Hide;

Begin Draw(getbkcolor); End;

Procedure TGraphObj.MoveTo;

Begin Hide; x:= x + dx; y:= y + dy; Show; End;

 

TGraphObj TPoint, . , , TGraphObj, Toint Draw:

 

Type

TPoint = Object(TGraphObj)

Procedure Draw(acolor: word); Virtual;

End;

Procedure TPoint.Draw;

Begin PutPixel(x, y, color); End;

 

TPoint - TGraphObj. , MoveTo, . TGraphObj.MoveTo TPoint.Draw, . Init TPoint, . TPoint.Draw Init, .

-, . , :

 

TLine = Object(TGraphObj)

dx, dy: integer;

Constructor init(x1, x2, y1, y2: integer; acolor: word);

Procedure Draw(acolor: word); Virtual;

End;

 

dx, dy . TLine.Init TGraphObj x, y color. dx, dy.

 

Constructor TLine.init;

Begin

Inherited init(x1, y1, acolor);

dx:= x2 - x1; dy:= y2 - y1;

End;

 

TLine.init x, y, color, , TGraphObj.Init.

dx, dy . TLine.Draw dx dy.

 

Procedure TLine.Draw;

Begin

SetColor(acolor); Line(x, y, x + dx, y + dy);

End;

 

TCircle :

 

Type

TCircle = Object (TGraphObj)

r: Integer;

Constructor Init (ax, ay, ar: Integer; acolor: Word);

Procedure Draw (acolor: Word); Virtual;

End;

Constructor TCircle.Init;

Begin

Inherited Init(ax, ay, acolor);

r:= ar

End;

Procedure TCircle.Draw;

Begin

SetColor(acolor);

Circle (x, y, r)

End;

 

, , :

 

uses graph;

Type TGraphobj = Object

x, y: integer; color: word;

Constructor init(ax, ay: integer; acolor: word);

Procedure Draw(acolor: word); Virtual;

Procedure Show;

Procedure Hide;

Procedure Moveto(dx, dy: integer);

End;

TPoint = Object(TGraphObj)

Procedure Draw(acolor: word); Virtual;

End;

TLine = Object(TGraphObj)

dx, dy: integer;

Constructor init(x1, x2, y1, y2: integer; acolor: Word);

Procedure Draw(acolor: word);Virtual;

End;

Constructor TGraphobj.init;

Begin x:= ax; y:= ay;color:= acolor; End;

Procedure TGraphObj.Draw;

Begin End;

Procedure TGraphObj.Show;

Begin Draw(color); End;

Procedure TGraphObj.Hide;

Begin Draw(getbkcolor); End;

Procedure TGraphObj.MoveTo;

Begin Hide; x:= x + dx; y:= y + dy; Show; End;

Procedure TPoint.Draw;

Begin PutPixel(x, y, color); End;

Constructor TLine.init;

Begin

Inherited init(x1,y1,acolor);

dx:= x2 - x1; dy:= y2 - y1;

End;

Procedure TLine.Draw;

Begin

SetColor(acolor); line(x,y,x+dx,y+dy);

End;

Var d, m: integer; pp: TPoint; ll: TLine;

{ TPoint; ll TLine}

Begin

d:= detect;

Initgraph(d, m, c:\pascal\bgi); { }

if graphresult <> 0 then halt(1);

{ }

ll.init(10, 20, 10, 20, 3); ll.oveto (50, 50);

{ }

pp.init(10, 10, 4); pp.oveTo(50, 50);

readln;

end.

 

, . , : , , . . . .

.

 

Unit GraphApp;

Interface

Type

TGraphApp = Object

Procedure Init;

Procedure Run;

Destructor Done;

End;

Implementatin

Procedure TGraphApp.Init;

...

End;

...

End.

 

:

 

Program Grph_Objects;

Uses GraphApp;

Var App: TGraphApp;

Begin

App.Init;

App.Run;

App.Done

End.

 

App TGraphApp. .

:

 

Program Grph_Objects;

Uses GraphApp;

Type

PGraphApp = ^ TGraphApp;

Var App: PGraphApp;

Begin

App:= New(PGraphApp, Init);

App^.Run;

App^.Done

End.

 

GraphObj, :

 

Unit GraphApp;

Interface

Uses GraphObj; { }

Const NPoints = 100;

Type

{}

TGraphApp = Object

Points: Array [1.. Npoints] of Tpoint;

Line: Tline;

Rect: TRect;

Circ: TCircle;

ActiveObj: Integer;

Procedure Init;

Procedure Run;

Procedure Done;

Procedure ShowAll;

Procedure MoveActiveObj (dx, dy: Integer);

End;

Implementation

Uses Graph, Crt;

Procedure TGraphApp.Init;

{ . Npoints Tpoint, Tline, Tcircle Trect}

Var d, r, Err, k: Integer;

Begin

{ }

d:= Detect;

InitGraph (d, r, \bgi);

Err:= GraphResult;

If Err<>0 Then

Begin

writeln( ,Err); Halt;

End;

{ }

For k:= 1 to Npoints do

Points[k].Init(Random(GetMaxX),Random(GetMaxY), Random(15) + 1);

{ }

Line.Init(GetMaxX div 3, GetMaxY div 3, 2 * GetMaxX div 3,

2 * GetMaxY div 3, LighRed);

Circ.Init(GetMaxX div 2, GetMaxY div 2, GetMaxY div 5, White);

Rect.Init(2 * GetMaxX div 5, 2 * GetMaxY div 5, 3 * GetMaxX div 5,

3 * GetMaxY div 5, Yellow);

ShowAll; { }

ActiveObj:= 1 { }

End; {TGraphApp.Init}

Procedure TGraphApp.Run;

{ Tab }

Var

Stop: Boolean; { Esc}

Const d = 5; { }

Begin

Stop:= False;

{ }

Repeat

Case ReadKey Of

#27: Stop:= True; { Esc}

#9: Begin { Tab}

inc(ActiveObj);

If ActiveObj > 3 Then ActiveObj:= 3

End;

#0: case Readkey of

#71: MoveActiveObj(-d, -d); { }

#72: MoveActiveObj(0, -d); {}

#73: MoveActiveObj(d, -d); { }

#75: MoveActiveObj(-d, 0); {}

#77: MoveActiveObj(d, 0); {}

#79: MoveActiveObj(-d, d); { }

#80: MoveActiveObj(0, d); {}

#81: MoveActiveObj(d, d); { }

End

End;

ShowAll;

Until Stop

End; {TGraphApp.Run}

Destructor TGraphApp.Done;

{ }

Begin

CloseGraph

End; {TGraphApp.Done}

Procedure TgraphApp.ShowAll;

{ }

Var

k: Integer;

Begin

For k:= 1 to Npoints do Points[k].Show;

Line.Show;

Rect.Show;

Circ.Show;

End;

Procedure TGraphApp.MoveActiveObj;

{ }

Begin

Case ActiveObj of

1: Rect.MoveTo (dx, dy);

2: Circ.MoveTo (dx, dy);

3: Line.MoveTo (dx, dy);

End;

End;

End.





:


: 2016-11-18; !; : 1327 |


:

:

: , .
==> ...

2376 - | 1988 -


© 2015-2024 lektsii.org - -

: 0.078 .