Вы находитесь на странице: 1из 17

:

..
____________________________________________________________________________________
_


,
(). .

.
,
Borland International Graph (
79 , ,
), , ,
.
:
. ,
,
.
.
:
1.
Graph ( ): uses Graph;
2.
:
- , (gd) (gm):
var gd, gm: integer;
- :
gd:=Detect; ( gm gd:=detect; )
- :
InitGraph( gd, gm, , , );
.
3.
: CloseGraph;
:
Uses graph; { }
Var gd,gm:integer;
Begin
gd:=detect; { }
InitGraph(gd,gm, ); { }
...
{ }
CloseGraph; { }
End.


.
, (0,0). ()
, Y () .
, .
, .
, CP (Current Pointer). ,
.

:
..
____________________________________________________________________________________
_

, ,

(xm, ym) (x,y) .


(x,y)
(xm, ym). (
):
xm=x0+x*Mx ,
ym=y0-y*My,
Mx, My- x y,
,
x, y- ,
xm, ym- (640, 480),
x0, y0- .
Graph

SetColor

SetColor (a: word);

SetBkColor
SetFillStyle

SetBkColor (a: word);


SetFillStyle (a,b: word);

SetLineStyle

a , b
SetLineStyle (a,b,c: word);

SetTextStyle
SetFillPattern
ClearDivice
SetViewPort
ClearViewPort
PutPixel

, b-
(
),
SetTextStyle (a,b,c: word);
,

SetFillPattern (Pattern:
,
FillpatternType; Color:word); Pattern-

ClearDivice


SetViewPort (x1, y1 , x2, y2 : integer,
Clip:boolean);

ClearViewPort

PutPixel (a,b,c :integer);
(x,y)

:
..
____________________________________________________________________________________
_
Line
Rectangle

Line(x1, y1 , x2,y2 :integer);


Rectangle (x1, y1 , x2, y2:integer );

Bar
Bar3D
Circle

Bar (x1, y1 , x2, y2:integer);


Bar3D (x1, y1 , x2,y2, d:integer,
a:boolean);
Circle (x,y,r: word);

Arc

Arc(x, y, , , R:integer);

Ellipse

, -


Ellipse (x, y, , , Rx, Ry: integer);
, (x, y)
, -

FillEllipse

FillEllipse (x, y, Rx, Ry:integer);

MoveTo
MoveRel

Rx, Ry

MoveTo (x, y:integer);
MoveRel(x, y : integer);

OutText
OutTextxy
Sector

(x1, y1) (x2,y2)



(x1, y1) (x2, y2)


()
r
(x, y)

, (x,y)

(x, y)


x y
OutText (text: string);

OutTextxy(x, y: integer, text: string); (x, y)

Sector(x, y, , , Rx, Ry: integer);
, -

Graph

GetBkColor
GetColor
GetX
GetY
GetMaxX
GetMaxY
GetPixel



X
Y
X
Y
(x, y)



.
, - .
. ,
- .
,
InitGraph.
, SetViewPort (x1, y1, x2, y2
: integer, Clip:boolean) ; x1, y1 , x2, y2
. Clip ,
(Clip:= True) (Clip:=False).
, (0,0).
3

:
..
____________________________________________________________________________________
_
, ,
ClearDevice :
SetViewPort( 0, 0, GetMaxX, GetMaxY, true);
,
SetBkColor ClearViewPort
. ( )
SetFillStyle SetFillPattern.


, ,
.
Graph
PutPixel (x, y: integer, color:word);
x, y: , color .
Color :

Black
Blue
Green -
Gyan
Red
Magenta
Brown
LightGray -

0
1
2
3
4
5
6
7

DarkGray -
LightBlue
LightGreen -
LightGyan -
LightRed -
LightMagenta -
Yellow
White

8
9
10
11
12
13
14
15

.
PutPixel(320, 240, 4);
-
PutPixel(320,240, Red);

( ).
Line (x1, y1 , x2,y2 :integer);
x1, y1 , x2,y2 - , Line(1,1,600,1);
Line .
SetColor (: word); 1.
.
SetColor(Gyan);
Line(1,1,600,1);
: LineTo LineRel. LineTo
(x,y: integer) x,y.
LineRel (dx,dy: integer) (x,
y) x+dx, y+dy.
: , ,
, .. SetLineStyle(a,b,c:
word), a , 2; b
, , , 3.
, b 0.
, b = 4.
(), .
4

:
..
____________________________________________________________________________________
_
:
SetLineStyle(1,0,1);
Line(15,15, 150,130);

SetLineStyle(UserBitLn,$5555,ThickWidth);
Line(15,15, 150,130);

SolidLn
DottedLn
CenterLn
DashedLn
UserBitLn

0
1
2
3
4

NormWidth
ThickWidth

1
3

(1 )
(3 )

3
: , .
Program treug;
uses graph; { }
var gd,gm: integer; { , }
begin
gd:=detect; { }
initgraph(gd, gm, c/bp); { }
SetColor(4); { }
SetLineStyle(1,0,3); { }
Line(320, 240, 320, 180);
Line(320, 240, 390, 240);
Line(390, 240, 320, 180);
end.

.
: Rectangle (x1, y1 , x2, y2:integer ), x1, y1
, x2, y2- .
.

Bar (x1, y1 , x2, y2:integer), .
SetFillStyle. : Bar3D (x1, y1 , x2,y2, d:
integer, a:boolean) ().
, SetFillStyle. d
, .
( d:= (x2 - x1) div 4 ). a ,
(:=True) (a:=False).
:
1. SetColor(Green);
Rectangle (200, 100, 250,300);
5

:
..
____________________________________________________________________________________
_
2. SetFillStyle(1,3);
Bar(10,10,50,100);
3. SetFillStyle(1,3);
Bar3D(10,10,50,100,10,True);

,
Line. DrawPoly,
, .
DrawPoly( a: word, var PolyPoints)
PolyPoints ,
.
PolyPoints. , N
DrawPoly N+1 ,
N 1.
:
program tr; { }
uses crt, graph;
var gd, gm: integer;
pp: array[1..4] of PointType;
xm, ym, xmaxD4, ymaxD4:word;
begin
gd:= detect;
Initgraph(gd, gm, c/bp);
xm:=GetmaxX; ym:=GetmaxY;
xmaxD4:=xm div 4;
ymaxD4:= ym div 4;
{ }
pp[1].x := xmaxD4;
pp[1].y := ymaxD4;
pp[2].x := xm - xmaxD4;
pp[2].y := ymaxD4;
pp[3].x := xm div 2;
pp[3].y := ym - ymaxD4;
pp[4] :=pp[1];
SetColor(4); { }
DrawPoly(4,pp); {4 +1}
readln;
CloseGraph
end.
.
FillPoly(a: word, var PolyPoints).
, DrawPly. ,
.
:
program g;
uses crt, graph;
6

:
..
____________________________________________________________________________________
_
const
Star: array[1..18] of integer = (75, 0, 100, 50, 150, 75, 100, 100, 75, 150, 50, 100, 0, 75, 50, 50, 75, 0);
var
gd, gm: integer;
begin
gd:= detect;
initgraph(gd, gm, c/bp);
SetFillStyle(1,2);
FillPoly(9,Star); {9 + 1}
CloseGraph;
end.


:
Cicrle(x, y, r: word), x, y , r .
, - 50
(450, 100):
SetColor(LightGreen);
Circle(450, 100, 50);
Arc(x, y: integer, , , R:integer), x, y , , - , R .
.
SetColor. =0 =360,
.
, 0 90
Circle(450, 100, 50) :
SetColor(Red);
Arc(450, 100, 0, 90,50);
Ellipse (x, y: integer, , , Rx,
Ry: integer), x, y , Rx, Ry: . =0
=360 . , :
SetColor(9);
Ellipse(100, 100, 0, 360, 50,50);
. ,
FillEllipse (x, y: integer, Rx, Ry: integer).
SetFillStyle (a, b: word), ( 4),
b ( 1). , - ,
:
SetFillStyle(WideDotFill, Green); { }
SetColor(12); { }
FillEllipse(300, 150, 50, 50);

EmptyFill
SolidFill
LineFill
LtslashFill
SlashFill

0
1
2
3
4



--, color
//
, color
//
, color

:
..
____________________________________________________________________________________
_
BkslashFill

LtbkSlahFill

HatchFill

XhatchFill

InterLeaveFill

WideDotFill
CloseDotFill
UserFill

10
11
12

\\
, color
\\
, color
-
, color
-
,
color
-
,
color



, color

4
:
PieSlice (x, y: integer, , , R: word), . x, y
, ,
;
Sector (x, y: integer, , , Rx, Ry: word), .
x, y , , Rx, Ry ,
.
PieSlice:
SetFillStyle(10, 10); { }
SetColor(12); { }
PieSlice(100, 100, 0, 90, 50);
Sector:
SetFillStyle(11, 9); { }
SetColor(LightMagenta); { }
Sector(300, 150, 180, 135, 60, 70);


.
OutText OutTextXY.
OutText(Textst: string) ,
. , OutText( );
.
OutTextXY(x, y: integer, Textst: string),
x, y , Textst String.
, OutTextXY(60, 100, )

Graph , .
Str,
+ .
: Max:=34.56;
Str(Max : 6 : 2, Smax);{ Smax}
OutTextXY(400, 40, = + Smax);
8

:
..
____________________________________________________________________________________
_

IntSt RealSt:
function IntSt(Int: integer) : string;
var Buf : string[10];
begin
Str(Int, Buf);
IntSt := Buf;
end;
function RealSt(R : real, Dig, Dec : integer) : string;
var Buf: string[20];
begin
Str(R : Dig : Dec, Buf);
RealSt := Buf;
end;
OutText OutTextXY. :
x:= 5.295643871;
OutTextXY(20, 20, x=+RealSt(x,11,9));
x=5.29564443871


( 5) . :
. , ,
.

DefaultFont, , , ,
.

TriplexFont

Trip.chr

SmallFont

Litt.chr

SansSerifFont

Sans.chr

GothicFont

Goth.chr

5
.
. ,
TurboFont, BgiToolKit.
SetTextStyle(Font,d,c:word), Font
, d ( ), .
5.
,
MoveTo, .
. =1, 8 8, =
2, 16 16 .. 10- .
2 ( ) DefaultFont
:
9

:
..
____________________________________________________________________________________
_
SetTextStyle(0,11); { }
OutTextXY(200,200, );
SetTextStyle(0,0,2); { }
OutTextXY(200,220, );


. SetTextJustify(Horiz,
Vert : word) , Horiz Vert
( 6).

LeftText
CenterText
RightText

0
1
2

BottomText
CenterText
TopText

0
1
2

6
x2:
SetTextJustify(1, 1);
OutTextXY(100,100, X);
SetTextJustify(1, 0);
OutTextXY(108,100, 2);



.
.
, . ,
(x0, y0) , (x, y)
(x-x0, y-y0).
, .

, .
, x y
.
10

:
..
____________________________________________________________________________________
_
:
- (

,
,
);
- (
:
(/) = ( /) / ( /), ,
.
640 480.
, , x,
y .
, .
. y=x2
1
program f;
uses graph;
var gd, gm: integer;
x, y: real;
begin
gd:= detect;
initgraph( gd, gm, c:\ bp);
SetColor(5);
Line(0, 240, 640, 240);
Line(320, 0, 320, 480);
x:= -20;
While x<=20 do
begin
y:= -Sqr(x);
PutPixel(round( x *5) + 320, round(y*5) +240, 15);
x:=x + 0.01;
end;
end.
2
program f;
uses graph, crt;
var gd, gm: integer;
x, y, mx, my, m,x1, x2, y1, y2,h: real;
function f(x:real): real;
begin
f:= Sqr(x);
end;
clrscr;
Write( );
Read(x1, x2);
y1:=f(x1);
mx:=640 /(x2 x1);
11

:
..
____________________________________________________________________________________
_
my:=480 / (y1 0);
If mx< my Then m:=mx
else m:= my;
h:= 1/m; x:=x1;
gd:= detect;
initgraph(gd, gm, c:\ bp);
SetColor (5);
Line(0, 240, 640, 240);
Line(320, 0, 320, 480);
While x<= x2 do
begin
y:= -f(x);
PutPixel(round(x *m) +320, round(y*m) +240, 15);
x:= x+ h;
end;
end.

:
nx:=round((x-xmin)/(maxx-minx)*nx_max);
ny:=round((y-ymax)/(maxy-miny)*ny_max);
: x,y ;
xmax, xmin x ;
ymax, ymin - y ;
nx_max ,
Getmaxx;
ny_max - ,
Getmaxy;
.
, .
3
program grafik;
uses graph,crt;
var xmin,xmax,ymin,ymax:real;
x,dx:real;
grDriver: Integer;
grMode: Integer;
ErrCode: Integer;
function nx(x:real):integer;
begin nx:=round((x-xmin)/(xmax-xmin)*getmaxx) end;
function ny(y:real):integer;
begin ny:=round((y-ymax)/(ymax-ymin)*getmaxy) end;
function y(x:real):real;
begin y:=sqr(x) end;
begin
grDriver := Detect;
InitGraph(grDriver, grMode,'u:\win95\bp7\bgi');
ErrCode := GraphResult;
if ErrCode = grOk then
12

:
..
____________________________________________________________________________________
_
begin
xmax:=5;xmin:=-5;
ymax:=5;ymin:=-5;
dx:=0.1;
setcolor(14);
Line(GetMaxX div 2,0, GetMaxX div 2, GetMaxY);
Line(0,GetMaxY div 2, GetMaxX, GetMaxY div 2);
setcolor(13);
x:=-4;
while x<=4 do
begin line(nx(x),-ny(y(x)),nx(x+dx),-ny(y(x+dx)));
x:=x+dx
end;
Readln;
CloseGraph;
end
else
Writeln('Graphics error:', GraphErrorMsg(ErrCode));
end.
: line, putpixel, ..
.
, .
, y=f(x), ,
.
.
()
x = a cos t ( 1+ cost), y = a sin t( 1+cost), a > 0, t [0, 2 )
:
SetColor (5);
Line(0, 240, 640, 240);
Line(320, 0, 320, 480);
t:=0; a:=3;
While t<= 3.1415 do
begin
x:=a*cos(t)*(1+cos(t));
y:= - a sin(t)*(1+cos(t));
PutPixel(x*5 +320, y*5 +240, 15);
x:= x+ 0.01;
end;

.
, ,
, , . Random.
[0, 1).
Random(I: word), 0 I.
,
13

:
..
____________________________________________________________________________________
_
Randomize,
.
.
:
Randomize
x:=random(640); y:=Random(480); c:=Random(15);
PutPixel(x, y, c);
. 5000 .
:
For i:=1 to 5000 do
begin
x:=Random(640); y:=Random(480); c:=Random(15);
PutPixel(x, y, c);
end;


.
.
I .
: (
) .
,
, ,
.
1. , .
program Model_At;
uses Crt, Graph;
const Ra=100;{ }
Rc=10; { }
Re=4; { }
k=0.5; { }
Dr=30; { }
Step1=0.2; { }
Step=100; { }
var cx, cy, y, y1, y2, x, x1, x2, x3, y3:integer;
I, I1, I2, I3: real; gd, gm: integer;
begin
clrscr;
gd:=detect; initgraph(gd, gm, );
SetTextStyle(0, 0, 2); OutTextXY(200, 30, );
cx:= GetMaxX div 2; { - }
cy:= GetMaxY div 2;
PieSlice(cx, cy, 0, 360, Rc);{ }
SetColor(Red); SetLineStyle(0, 0, 3);
Line(cx-7, cy, cx+7, cy); Line(cx, cy-5, cx, cy+5);
SetLineStyle(0,0,1); SetFillStyle(1, 1);
I:=Pi/4; { 4 }
I1:= - Pi/4; I2:= - Pi/2; I3:= Pi/2;
14

:
..
____________________________________________________________________________________
_
SetTextStyle(0, 0, 1);SetColor(jellow);
OutTextXY(180, 420, );
While not KeyPressed do {, }
begin
{ }
x:=Round (Ra*cos(I)) +cx; Y:= Round (k+Ra*sin(I)) +cy;
x1:= Round((Ra+Dr)*cos(I1)) +cx; y1:= Round (k*(Ra+Dr)*sin(I1)) +cy;
x2:= Round((Ra-Dr)*cos(I2)) +cx; y2:= Round (k*(Ra-Dr)*sin(I2)) +cy;
x3:= Round((Ra-Dr)*cos(I3)*2.3) +cx; y3:= Round (k*(Ra-Dr)*sin(I3)*2.3) +cy;
{ }
SetColor(1);
Circle (x, y, Re); PutPixel(x, y, 2);
Circle (x1, y1, Re); PutPixel(x1, y1, 2);
Circle (x2, y2, Re); PutPixel(x2, y2, 2);
Circle (x3, y3, Re); PutPixel(x3, y3, 2);
Delay(Step);
{ }
SetColor(0);
Circle (x, y, Re); PutPixel(x, y, 2);
Circle (x1, y1, Re); PutPixel(x1, y1, 2);
Circle (x2, y2, Re); PutPixel(x2, y2, 2);
Circle (x3, y3, Re); PutPixel(x3, y3, 2);
{ }
I:=I + Step1; I1:=I1 Step1; I2:=I2 + Step1; I3:=I3 + Step1;
end; { }
CloseGraph;
end.
II . .
ImageSize(x1, y1, x2, y2: integer):word ,
, x1,y1
x2, y2 .
GetImage(x1, y1, x2, y2:integer, var Buf)
, x1, ..,y2 ,
Buf ,
. Buf , ImageSize
.
PutImage(x1, y1, x2, y2:integer, var Buf, Mode:word)
, GetImage. X, Y
,
; Buf , , Mode
. ,
.
, (
, , ). Mode
(.
7) .

NormalPut

15

:
..
____________________________________________________________________________________
_
XorPut

OrPut

AndPut

NotPut


,





, 0,

2. , .
program NLO;
uses crt, graph;
const k=20; Pause=50;
var
gd, gm, xmin, xm, ymin, ym, x, y, tx, ty, rx, ry, size, i, dx, dy, width, height: integer;
sauser:Pointer;
begin
Randomize;
gd:= detect; initgraph(gd, gm, );
SetTextStyle(0, 0, 2); OutTextXY(50, 10, );
{ }
x:=R*5; y:=R*2; xm:=GetmaxX- 5; ym:=GetmaxY-25;
Ellipse(x, y, 0, 360, R, R div 3+2);
Ellipse(x, y-4, 190, 357, R, R div 3);
Line(x + 7, y - 6, x + 10, y - 12);
Line(x -7, y - 6, x + 10, y - 12);
Circle(x + 10, y - 10, 2);
Circle(x -10, y - 10, 2);
FloodFill(x+1, y+4, White);
{ }
Tx:= x-R; Ty:=y-14; Rx:;=x+R; Ry:=y+R div3 +3;
Width:=Rx-Tx+1; Size:=ImageSize(Tx, Ty, Rx, Ry);
GetMem(sauser, Size);
GetImage(Tx, Ty, Rx, Ry, sauser^);
{ }
PutImage(Tx, Ty, sauser^, XorPut);
{ }
SetStyle(1, blue); { }
SetColor(White);
{ }
Rectangle(xmin, ymin, GetmaxX, GetmaxY);
SetViewPort(xmin, ymin, GetmaxX, GetmaxY, ClipOn);
FloodFill(xmin+1, ymin+1, White);
For i:=1 to 500 do { 500 }
PutPixel(Random(GetmaxX), Random(GetmaxY- ymin), 15);
{ }
x:=xm div 3 xmin; y:=ym div 3 ymin; dx:=6; dy:=6;
Repeat {: , }
PutImage(x, y, sauser^, XorPut); { }
Delay (Pause);{ }
PutImage(x, y, sauser^, XorPut); { }
16

:
..
____________________________________________________________________________________
_
{ }
If (x<xmin) Or (y<ymin) Or (x+Width +1> xm) Or (y+Height +1> ym) Then
begin { - , ,
}
If (x- Dx< xmin) then x:= xmin else x := x- Dx;
If (y- Dy< ymin) then y:= ymin else y := y- Dy;
Dx:= GetmaxX div 10 - Random(GetmaxX div 4);
Dy:= GetmaxY div 10 - Random(GetmaxY div 4);
end else
begin { - , ,
}
If (x + Dx< xm) then x:= x + Dx else x:= Random(GetmaxX) - Random(GetmaxX div 4);
If (y + Dy< ym) then y:= y + Dy else y:= Random(GetmaxY) - Random(GetmaxY div 3);
end;
until KeyPressed; {, }
FreeMem (sauser, Size);
Closegraph;
end;
end.

17