Да, теперь буду знать, программу исправил, сделал только один вызов в начале программы, теперь я чувствую что программу можно назвать почти универсальной для любого графика типа y=f(x). В дальнейшем займусь подробным изучением аппаратной части, что бы не наломать дров) Спасибо вам огромное!!)
Оставлю код своей программы здесь чтобы желающие могли им воспользоваться для примера. Можете её модернизировать, я разрешаю)
Код: Выделить всё
program GoodWorkGraph;
uses Graph,SysUtils,CRT,Math;
var
c:char;
x,y,y1,step_x,step_y:real;
CenterCordinatXY:array [0..1] of integer;
sizeXp,sizeXm,sizeYp,sizeYm:integer;
const
gradient=40;
x_max=639;
y_max=479;
l=10;
speed=5;
{ ********************************************************************** }
procedure GraphCHK;
var Gd,Gm:smallint;
begin
Gd:=VGA;
Gm:=VGAHi;
InitGraph(Gd,Gm,'');
if GraphResult <> grOk then
begin
write('Ошибка');
halt(1);
end;
end;
{ ********************************************************************** }
procedure SetCenter(var CnCrd:array of integer); //Установка центра
var st_x,st_y:real;
begin
st_x:=(x_max+1)/(sizeXp+sizeXm);
st_y:=(y_max+1)/(sizeYp+sizeYm);
CnCrd[0]:=round(st_x*sizeXm);
CnCrd[1]:=y_max-round(st_y*sizeYm);
end;
procedure SetSize (var sXp,sXm,sYp,sYm:integer); //Установка размера графика как в положительных так и отрицательных
begin //значениях X и Y
write('set size X+: '); readln(sXp);
write('set size X-: '); readln(sXm);
write('set size Y+: '); readln(sYp);
write('set size Y-: '); readln(sYm);
end;
procedure DrawGrid;
var loop,metka,gipfu:integer;
begin
Line(0,CenterCordinatXY[1],x_max,CenterCordinatXY[1]);
Line(CenterCordinatXY[0],0,CenterCordinatXY[0],y_max);
step_x:=x_max/(sizeXp+sizeXm);
step_y:=y_max/(sizeYp+sizeYm);
{******************************************************************************}
MoveTo(CenterCordinatXY[0],CenterCordinatXY[1]); //обрисовка меток по X+
loop:=0; metka:=0;
while GetX<x_max do
begin
if (step_x>=20) then
begin
if loop mod round(step_x) = 0 then
begin
Line(GetX,GetY+l,GetX,GetY-l);
OutTextXY(GetX-l,GetY+2*l,IntToStr(metka));
inc(metka);
end;
end
else
begin
gipfu:=round(gradient/step_x);
if loop mod round(step_x*gipfu) = 0 then
begin
Line(GetX,GetY+l,GetX,GetY-l);
OutTextXY(GetX-l,GetY+2*l,IntToStr(metka));
inc(metka,gipfu);
end;
end;
inc(loop);
MoveTo(GetX+1,GetY);
end;
{***************************************************************************************************************}
MoveTo(CenterCordinatXY[0],CenterCordinatXY[1]); //обрисовка меток по X-
loop:=0; metka:=0;
while GetX>0 do
begin
if (step_x>=20) then
begin
if loop mod round(step_x) = 0 then
begin
Line(GetX,GetY+l,GetX,GetY-l);
OutTextXY(GetX-l,GetY+2*l,IntToStr(-metka));
inc(metka);
end;
end
else
begin
gipfu:=round(gradient/step_x);
if loop mod round(step_x*gipfu) = 0 then
begin
Line(GetX,GetY+l,GetX,GetY-l);
OutTextXY(GetX-l,GetY+2*l,IntToStr(-metka));
inc(metka,gipfu);
end;
end;
inc(loop);
MoveTo(GetX-1,GetY);
end;
{***************************************************************************************************************}
MoveTo(CenterCordinatXY[0],CenterCordinatXY[1]); //обрисовка меток по Y+
loop:=1; if (step_y>=20) then metka:=1 else metka:=round(gradient/step_y);
while GetY<y_max do
begin
if (step_y>=20) then
begin
if loop mod round(step_y) = 0 then
begin
Line(GetX-l,GetY,GetX+l,GetY);
OutTextXY(GetX+l+2,GetY-2,IntToStr(metka));
inc(metka);
end;
end
else
begin
gipfu:=round(gradient/step_y);
if loop mod round(step_y*gipfu) = 0 then
begin
Line(GetX-l,GetY,GetX+l,GetY);
OutTextXY(GetX+l+2,GetY-2,IntToStr(metka));
inc(metka,gipfu);
end;
end;
inc(loop);
MoveTo(GetX,GetY-1);
end;
{***************************************************************************************************************}
MoveTo(CenterCordinatXY[0],CenterCordinatXY[1]); //обрисовка меток по Y-
loop:=1; if (step_y>=20) then metka:=1 else metka:=round(gradient/step_y);
while GetY>0 do
begin
if (step_y>=20) then
begin
if loop mod round(step_y) = 0 then
begin
Line(GetX-l,GetY,GetX+l,GetY);
OutTextXY(GetX+l+2,GetY-2,IntToStr(-metka));
inc(metka);
end;
end
else
begin
gipfu:=round(gradient/step_y);
if loop mod round(step_y*gipfu) = 0 then
begin
Line(GetX-l,GetY,GetX+l,GetY);
OutTextXY(GetX+l+2,GetY-2,IntToStr(-metka));
inc(metka,gipfu);
end;
end;
inc(loop);
MoveTo(GetX,GetY+1);
end;
end;
{****************************************************************************}
function F(x:real):real; //y=ln(x+5)
begin
F:=ln(x+5)*step_y;
end;
procedure DrawFuntcion; //Обрисовка графика
var
loop:integer;
begin;
x:=-CenterCordinatXY[0]/step_x;y:=0;y1:=0; loop:=-CenterCordinatXY[0];
while loop<x_max-CenterCordinatXY[0] do
begin
y:=F(x);
y1:=F(x+(1/step_x));
if not(IsInfinite(y) or IsNaN(y)) then
if not (IsInfinite(y1) or IsNaN(y1)) then
Line(loop+CenterCordinatXY[0],CenterCordinatXY[1]-round(y),loop+1+CenterCordinatXY[0],CenterCordinatXY[1]-round(y1));
x:=x+(1/step_x);
inc(loop);
end;
end;
procedure MoveLeft;
begin
CenterCordinatXY[0]:=CenterCordinatXY[0]+speed;
ClearDevice;
DrawGrid;
DrawFuntcion;
end;
procedure MoveRight;
begin
CenterCordinatXY[0]:=CenterCordinatXY[0]-speed;
ClearDevice;
DrawGrid;
DrawFuntcion;
end;
procedure MoveUp;
begin
CenterCordinatXY[1]:=CenterCordinatXY[1]+speed;
ClearDevice;
DrawGrid;
DrawFuntcion;
end;
procedure MoveDown;
begin
CenterCordinatXY[1]:=CenterCordinatXY[1]-speed;
ClearDevice;
DrawGrid;
DrawFuntcion;
end;
begin
Set8087CW(Get8087CW or %111111);
SetSize(sizeXp,sizeXm,sizeYp,sizeYm);
SetCenter(CenterCordinatXY);
GraphCHK;
DrawGrid;
DrawFuntcion;
repeat
c:=ReadKey;
if c=#75 then MoveLeft;
if c=#80 then MoveDown;
if c=#77 then MoveRight;
if c=#72 then MoveUp;
until c=#27;
CloseGraph;
end.