-
InitGraph. .
:
Procedure InitGraph(var Driver,Mode: Integer; Path: String);
Driver - Integer, ;
Mode - , ;
Path - String, , , .
, .
.
. :
const
Detect=0;{ }
CGA=1;
MCGA=2;
EGA=3;
EGA64=4;
EGAMono=5;
IBM8514=6;
HercMono=7;
ATT400=8;
VGA=9;
PC3270=10;
. , , Mode, :
const | ||
{ CGA: } | ||
CGACO = 0; | { , | 0} |
CGAC1 = 1; | { , | 1} |
CGAC2 = 2; | { , | 2} |
CGAC3 = 3; | { , | 3} |
CGAHi = 4; | { } | |
{ MCGA:} | ||
MCGACO = 0; | { CGACO} | |
MCGAC1 = 1; | { CGAC1} | |
MCGAC2 = 2; | { CGAC2} | |
MCGAC3 = 3; | { CGAC3} | |
MCGAMed = 4; | { CGAHi} | |
MCGAHi = 5; | {640x480} | |
{ EGA:} | ||
EGALo = 0; | {640x200, 16 } | |
EGAHi = 1; | {640x350, 16 } | |
EGAMonoHi = 3; | {640x350, 2 } | |
{ HGC | HGC+:} | |
HercMonoHi = 0; | {720x348} | |
{400:} | ||
ATT400CO = 0; | { CGACO} | |
ATT400C1 = 1; | ( CGAC1} | |
ATT400C2 = 2; | { CGAC2} | |
ATT400C3 = 3; | { CGAC3} | |
ATT400Med = 4; | { CGAHi} | |
ATT400H1 = 5; | {640x400, 2 } |
{ VGA:}
VGALo = 0; {640x200}
VGAMed = 1; {640x350}
VGAHi = 2; {640x480}
PC3270H1 = 0; { HercMonoHi}
{ 18514}
IBM8514LO =0; {640x480, 256 }
IBM8514H1 = 1; {1024x768, 256 }
, , CGA.BGI TP\BGI 320x200 2.
:
Uses Graph;
var
Driver, Mode: Integer;
begin
Driver:= CGA;{}
Mode:= CGAC2;{ }
InitGraph(Driver, Mode,' :\TP\BGI');
.......
, :
|
|
Driver:= Detect;
InitGraph(Driver, Mode, 'C:\TP\BGI');
, Driver Mode , .
, , , .. , .
, CGA - Driver = Detect Driver 1 (CGA) Mode - 4 (CGAHi), VGA Driver = 9 (VGA) Mode = 2 (VGAHi).
GraphResult. Integer, .
, , - , :
const
grOk = 0;{ }
grlnitGraph =-1;{He }
grNotDetected =-2;{ }
grFileNotFind =-3;{ }
grlnvalidDriver =-4;{ }
grNoLoadMem =- 5;{ }
grNoScanMem = - 6;{ }
grNoFloodMem =- 7;{ }
grFontNotFound = -8;{ }
grNoFontMem =- 9;{ }
grlnvalidMode =-10;{ }
grError =-11;{ }
grIOError =-12;{ -}
grlnvalidFont =-13;{ }
grInvalidFontNum=-14; { }
GraphResult , .
GraphErrorMsg.
String, . :
Function GraphErrorMsg(Code: Integer): String;
Code - , GraphResult.
, :
var
Driver, Mode, Error:Integer;
begin
Driver:= Detect;{ }
InitGraph(Driver, Mode,' ');{ }
Error:= GraphResult;{ }
if Error <> grOk then{ }
begin{ }
WriteLn(GraphErrorMsg(Error));{ }
.......
end
else{ }
.......
InitGraph (, CGA.BGI CGA).
InitGraph.
, , DRIVERS PASCAL D, :
InitGraph(Driver, Mode, 'd:\Pascal\Drivers');
.
InitGraph Driver .
, .
|
|
, , .
CloseGraph.
. :
Procedure CloseGraph;
RestoreCRTMode.
.
CloseGraph , . :
Procedure RestoreCRTMode;
GetGraphMode.
Integer, .
:
Function GetGraphMode: Integer;
SetGraphMode.
.
:
Procedure SetGraphMode(Mode: Integer);
Mode - .
:
Uses Graph;
var.
Driver, Mode, Error: Integer;
begin
{ }
Driver:= Detect;
InitGraph(Driver, Mode, '');
Error:= GraphResult; { }
i£ Error <> grOk then { }
WriteLn(GraphErrorMsg(Error)) { }
else
begin { }
WriteLn (' ');
WriteLn (' "Enter"...':20);
ReadLn;
{ }
RestoreCRTMode;
WriteLn (' ...');
ReadLn;
{ }
SetGraphMode (GetGraphMode);
WriteLn (' ...');
ReadLn;
CloseGraph
end
end.
, WriteLn.
CGA, , , .
DetectGraph.
. :
Procedure DetectGraph(var Driver,Mode: Integer);
Driver - ; Mode - .
GetGraphMode Mode .
GetDriverName.
String, . :
Function GetDriverName: String;
GetMaxMode.
Integer, . :
Function GetMaxMode: Integer;
GetModeName.
String, . :
Function GetModName(ModNumber: Integer): String;
ModNumber - .
, , .
Uses Graph;
var
a,b: Integer;
begin
a:= Detect;
InitGraph(a, b, '');
WriteLn(GetDriverName);
for a:= 0 to GetMaxMode do
WriteLn(GetModeName(a):10);
ReadLn;
CloseGraph
end.
GetModeRange.
. :
Procedure GetModeRange(Drv: Integer; var Min, Max: Integer);
Drv - ; Min - Integer, ; - , .
Drv, -1.
. .
|
|
Uses Graph;
var
D,L,H: Integer;
const
N: array [1..11] of String [8] =
('CGA ', 'MCGA ', 'EGA ',
'EGA64 ', 'EGAMono ', 8514 ',
'HercMono', 'ATT400 ', 'VGA ',
'PC3270 ', ' ');
begin
WriteLn(' . .');
for D:= 1 to 11 do
begin
GetModeRange(D, L, H);
WriteLn(N[D], L:7, H:10)
end
end.
- , ,
, .
, , , , , 0,0. , , - .
GetMaxX GetMaxY.
Word, . :
Uses Graph;
var
a,b: Integer;
begin
a:= Detect; InitGraph(a, b, '');
WriteLn(GetMaxX, GetMaxY:5);
ReadLn;
CloseGraph
end.
GetX GetY.
Integer, .
, , .
SetViewPort.
.
:
Procedure SetViewPort(XI,Y1,X2,Y2: Integer; ClipOn: Boolean);
X1...Y2 - (XI,Y1) (X2,Y2) ; - Boolean, .
. ClipOn True, , , , .
:
const
ClipOn = True; { }
ClipOff = False; {He }
.
. (. . 14.1).
.
Uses Graph,CRT;
var
x,y,e: Integer;
xll,yll,xl2,yl2, { 1- }
x21,x22, { 2-}
R, { }
k: Integer;
begin
DirectVideo:= False { CRT}
{ }
:= Detect; InitGraph(x, , '');
{ }
:= GraphResult; if e <> grOk then
WriteLn(GraphErrorMsg (e)) {}
else
begin { }
{ }
x11:=GetMaxX div 60;
x12:=GetMaxX div 3;
y11:=GetMaxY div 4; y12:=2*y11;
R:=(x12-x11) div 4; x21:=x12*2;
x22:=x21+x12-x11;
{ }
WriteLnt'ClipOn:':10,'ClipOff:':40);
Rectangle(x11, y11, x12, y12); Rectangle(x21, y11 x22, y12);
{ 1- }
SetViewPort(x11, y11, x12, y12, ClipOn);
for k:= 1 to 4 do
Circle(0,y11,R*k);
{ 2- }
SetViewPort(x21, y11, x22, y12, ClipOff);
for k:= 1 to 4 do
Circle(0,y11,R*k);
{ }
if ReadKey=#0 then k:= ord(ReadKey);
CloseGraph
end
end.
GetViewSettings.
. :
|
|
Procedure GetViewSettings(var Viewlnfo: ViewPortType);
Viewlnfo - ViewPortType. Graph :
type
ViewPortType = record
x1,y1,x2,y2: Integer; { }
Clip: Boolean { }
end;
MoveTo.
. :
Procedure MoveTo(X,Y: integer);
X, Y - .
, , .
MoveRel.
.
Procedure MoveRel(DX,DY: Integer);
DX.DY- .
, .
ClearDevice.
.
, , SetBkColor.
:
Procedure ClearDevice;
ClearViewPort.
, - . .
. :
Procedure ClearViewPort;
, (.).
.
Enter.
.
Uses CRT,Graph;
var
x1,y1,x2,y2,Err: Integer;
begin
{ }
xl:= Detect; InitGraph(xl,x2,'');
Err:= GraphResult; if ErrogrOk then
WriteLn(GraphErrorMsg(Err))
else
begin
{ }
x1:= GetMaxX div 4,-y1:= GetMaxY div 4;
x2:= 3*x1; y2:= 3*y1;
{ }
Rectangle(x1,y1,x2,y2);
SetViewPort(x1+1,y1+1,x2-1,y2-1,ClipOn);
{ }
repeat
ircl(Random(Ge tMaxX),Random(Ge tMaxX)
Random(GetMaxX div 5))
until KeyPressed;
{ Enter}
ClearViewPort;
OutTextXY(0,0,'Press Enter...1);
ReadLn;
CloseGraph
end
end.
GetAspectRatio.
, .
:
Procedure GetAspectRatio(var X,Y: Word);
X, Y - Word. , , . , , .. , L ,
GetAspectRatio (Xasp, Yasp);
Rectangle(x1, y1, x1+L*round (Yasp/Xasp), y1+L);
L ,
Rectangle (x1,y1,x1+L,y1+L*round(Xasp/Yasp));
SetAspectRatio.
. :
Procedure SetAspectRatio(X,Y: Word);
X, Y- .
20 (.).
.
Uses Graph,CRT;
const
R =.50;
dx = 1000;
var
d,m,e,k: Integer;
Xasp,Yasp: Word;
begin
d:= Detect;
InitGraph(d, m,.'');
e: = GraphResult;
if e <> grOk then
WriteLn(GraphErrorMsg(e))
else
begin
GetAspectRatio(Xasp, Yasp);
for k:= 0 to 20 do
begin
SetAspectRatio(Xasp+k*dx,Yasp);
Circle(GetMaxX div 2,GetMaxY div 2,R)
end;
if ReadKey=#0 then k:= ord(ReadKey);
CloseGraph
end
end.
SetActivePage.
.
:
Procedure SetActivePage(PageNum: Word);
PageNum - .
, (EGA, VGA ..).
, Write/WriteLn , ( ).
.
SetVisualPage.
.
:
Procedure SetVisualPAge(PageNum: Word);
PageNum - .
, (EGA, VGA ..).
|
|
.
- .
Enter .
Uses Graph;
var
d,m,e: Integer;
s: String;
begin
d:= Detect; InitGraph(d, m, '');
e:= GraphResult; if e <> grOk then
WriteLn (GraphErrorMsg(e))
else { . , :}
if d in [HercMono,EGA,EGA64,MCGA,VGA] then
begin { }
if d<>HercMono then
SetGraphMode(m-1);
{ }
Rectangle(10,10,GetMaxX div 2,GetMaxY div 2);
OutTextXY(0,0,'Page 0. Press Enter...');
{ }
SetActivePage (1);
Circle(GetMaxX div 2, GetMaxY div 2, 100);
OutTextXY(0,GetMaxY-10,'Page 1. Press Enter...');
{ }
ReadLn;
SetVisualPage(1);
ReadLn;
SetVisualPage (0);
ReadLn;
CloseGraph
end
else
begin { }
s:= GetDriverName; CloseGraph;
WriteLn(' ',s,' 1 ')
end
end.
if doHercMono then
SetGraphMode(m-1);
EGA, MCGA, VGA.
, Driver=Detect ; , , .
-
PutPixel.
.
:
Procedure PutPixel(X,Y: Integer; Color: Word);
X, Y- ; Color - .
, , .
. .
Uses CRT, Graph;
type
PixelType = record
x, : Integer; end;
const
N = 5000; { ""}
var
d,r,e,k: Integer;
x1,y1,x2,y2: Integer;
a: array [1..N] of PixelType; {}
begin
{ }
d:= Detect; InitGraph(d, r, ' ');
e:= GraphResult; if e<>grOk then
WriteLn(GraphErrorMsg(e))
else
begin
{ }
x1:= GetMaxX div 4;
y1:= GetMaxY div 4;
x2:= 3*x1;
y2:= 3*y1;
Rectangle(x1,y1,x2,y2);
SetViewPort(x1+1,y1+1,x2-1,y2-1,ClipOn);
{ ""}
for k:= 1 to N do with a[k] do begin
x:= Random(x2-x1);
:= Random(y2-y1)
end;
{ }
repeat
for k:= 1 to N do
with a[k] do { ""}
PutPixel(x,y,white);
if not KeyPressed then
for k:= N downto 1 do with a[k] do { ""}
PutPixel(x,y,black)
until KeyPressed;
while KeyPressed do k:= ord(ReadKey);
CloseGraph
end;
end.
GetPixel.
Word, . :
Function GetPixel(X,Y: Integer): Word;
X, Y - .
Line.
.
:
Procedure Line(X1,Y1,X2,Y2: Integer);
XL..Yl - (XI, Y1) (2, Y2) .
.
, .
.
Uses CRT, Graph;
var
d,r,e: Integer;
x1,y1,x2,y2: Integer;
begin
{ }
d:= Detect; InitGraph(d, r, '');
e:= GraphResult; if e <> grOk then
WriteLn(GraphErrorMsg(e))
else
begin
{ }
x1:= GetMaxX div 4;
y1:= GetMaxY div 4;
x2:= 3*x1;
y2:= 3*y1;
Rectangle(x1,y1,x2,y2);
SetViewPort(x1+1,y1+1,x2-1,y2-1,ClipOn);
{ }
repeat
SetColor(succ(Random(16))); { }
Line(Random(x2-x1), Random(y2-y1),
Random(x2-x1), Random(y2-y1))
until KeyPressed;
if ReadKey=#0 then d:= ord(ReadKey);
CloseGraph
end
end.
LineTo.
, .
:
Procedure LineTo(X,Y: Integer);
X, Y - , - .
LineRel.
, .
:
Procedure LineRel (DX, DY: Integer);
DX, DY- .
LineTo LineRel .
SetLineStyle.
.
:
Procedure SetLineStyle(Type,Pattern,Thick: Word)
Type, Pattern, Thick - , .
: const SolidLn= 0; { }
DottedLn= 1; { }
CenterLn= 2; {- }
DashedLn= 3; { }
UserBitLn= 4; { }
Pattern , (.. , = UserBitLn).
Pattern : , - .
, Pattern 16 .
.
Thick : const NormWidth = 1; { }
ThickWidth = 3; { }
, ( ) , .
, - (.).
.
.
Uses CRT, Graph;
const
style: array [0..4] of String [9] = (
'SolidLn ', 'DottedLn ', 'CenterLn 'DashedLn', 'UserBitLn');
var
d,r,e,i,j,dx,dy: Integer;
p: Word;
begin
{ }
d:= Detect; InitGraph(d, r, '');
e:= GraphResult; if e <> grOk then
WriteLn (GraphErrorMsg(e))
else
begin
{ }
dx:= GetMaxX div 6;
dy:= GetMaxY div 10;
{ }
for j:= 0 to 1 do { }
begin
for i:= 0 to 3 do { }
begin
SetLineStyle(i, 0, j*2+1);
Line(0,(i+j*4+l)*dy,dx,(i+j*4+l)*dy);
OutTextXY(dx+10, (i+j*4+l)*dy,style [i])
end
end;
{ }
j:= 0;
dy:= (GetMaxY+1) div 25;
repeat
OutTextXY(320,j*dy,'Pattern: ');
GotoXY(50,j+1);
ReadLn(p); if p <> 0 then
begin
SetLineStyle(UserBitLn,p,NormWidth);
Line(440,j*dy+4, 600, j*dy+4);
inc(j)
end
until p = 0;
CloseGraph
end
end.
1.1. : , . 1.2. : | |
2.1. : , . 2.2. | |
3.1. : , . 3.2. | |
4.1. : , . 4.2. | |
5.1.. : , 30. 5.2.. | |
6.1. : , . 6.2. | |
7.1. : , 7.2. | |
8.1. : , 30. 8.2. | |
9.1. : , 9.2. | |
10.1. : , 10.2. | |
11.1. : , . 11.2 | |
12.1. : . . , , , , . 12.2. | |
13.1. : . . , , . 13.2. | |
14.1. : . 14.2. | |
15.1. : , . 15.2. | |
16.1. : , .. 16.2. | |
17.1. : , 30 . 17.2. | |
18.1. : , . 18.2. | |
19.1. : , . 19.2. | |
20.1. : , . 20.2. | |
21.1. : , . 21.2. | |
22.1. : . 22.2. | |
23.1. : , . 23.2. | |
24.1. : , . 24.2. | |
25.1. : , 25.2. | |
26.1. : , 26.2. | |
27.1. : , . 27.2. | |
28.1. : . . , , . 28.2. | |
29.1. : , . 29.2. |