Ábrázoljuk a grafikus képernyőn a
következő függvényeket:
y=0.5x+2; (egyenes)
y=x4-6x2+3; (negyedfokú
függvény)
(x+6)2+(y-3)2=4;
(kör)
y=sin(x). (Sinus görbe)
A futási kép:
A program listája:
Program Grafikon;
Uses NewDelay, Crt,
Graph;
Const D=50;
Dx=0.1;
Var
Xm,Ym,
Xk,Yk, I,J: Integer;
Sz: String;
A,B,C, X,Y: Real;
Procedure GrInit;
Var
Gd,Gm:
Integer;
Begin
Gd:= InstallUserDriver('svga256',Nil); Gm:=4;
InitGraph(Gd,Gm,'C:\Tp\Bgi');
If GraphResult<>0 Then Halt;
Xm:= GetMaxX; Ym:= GetMaxY;
Xk:= Xm Div
2; Yk:= Ym Div 2;
End;
Function PontX(R: Real): Integer;
Begin
PontX:= Round(Xk+R*D);
End;
Function PontY(R: Real): Integer;
Begin
PontY:= Round(Yk-R*D);
End;
Begin
GrInit;
SetFillStyle(1,15); Bar(0,0, Xm,Ym);
SetColor(0);
Line(0,Yk, Xm,Yk); Line(Xk,0,
Xk,Ym);
MoveTo(Xm-5,Yk-5); LineTo(Xm,Yk); LineTo(Xm-5,Yk+5);
MoveTo(Xk-5,5); LineTo(Xk,0); LineTo(Xk+5,5);
Circle(Xk,Yk,4);
For I:= -10 To 10 Do
Begin
Line(Xk+I*D,Yk-4,Xk+I*D,Yk+4); Str(I,Sz);
If I<0 Then OutTextXY(Xk+I*D-7,Yk+6,Sz);
If I>0 Then OutTextXY(Xk+I*D-3,Yk+6,Sz)
End;
For I:= -7 To 7 Do
Begin
Line(Xk-4,Yk-I*D,Xk+4,Yk-I*D); Str(I,Sz);
If I<0 Then OutTextXY(Xk-22,Yk-I*D-4,Sz);
If I>0 Then OutTextXY(Xk-14,Yk-I*D-4,Sz);
End;
For I:= -10 To 10 Do
For J:= -7 To 7 Do
PutPixel(Xk+I*D,Yk-J*D,0);
SetColor(Red);
A:= 0.5; B:= 2; {y=0.5x+2}
X:= -10; MoveTo(PontX(X),PontY(A*X+B));
Repeat
X:= X+Dx; Y:= A*X+B; LineTo(PontX(X),PontY(Y));
Until X>10;
SetColor(Blue); {(x+6)2+(y-3)2=4}
Circle(PontX(-6),PontY(3),2*D);
SetColor(Black);
A:= 1; B:= -6; C:= 3; {y=x4-6x2+3}
X:= -6; MoveTo(PontX(X),PontY(A*X*X*X*X+B*X*X+C));
Repeat
X:= X+Dx; Y:= A*X*X*X*X+B*X*X+C;
LineTo(PontX(X),PontY(Y));
Until X>6;
{y=sin(x)}
SetColor(Green);
X:= -10; MoveTo(PontX(X),PontY(Sin(X)));
Repeat
X:= X+Dx; Y:= Sin(X); LineTo(PontX(X),PontY(Y));
Until X>10;
ReadKey;
CloseGraph;
End.