Специалист
Регистрация: 27.08.2008
Адрес: Санкт-Петербург
Сообщений: 27,807
Сказал(а) спасибо: 340
Поблагодарили 583 раз(а) в 208 сообщениях
Репутация: 113184
|
Цитата:
Сообщение от mary yu
Если не затруднит, можете представить исправленный код?
|
Ну что Вы, право, какие пустяки - 2-3 часика работы, связанной в основном с разгадыванием смысла задания, и вот:
Код:
program sharik;
uses graph,crt;
var
x1,x2:integer;
y1,y2:real;
x,xx,xx1,xx2:real;
y,yy:real;
dx:real;
l,b,k,i:integer;
w,h:integer;
mx,my:real;
x0,y0:integer;
st:string;
key:char;
function f(x:real):real;
begin
f:=x*x*x;
end;
begin
i:=0;
InitGraph(i,i,'i:\prg\tp\bgi');
ClearDevice;
SetColor(5);
SetTextStyle(DefaultFont,HorizDir,3);
SetTextJustify(CenterText,CenterText);
OutTextXY((GetMaxX div 2),(GetMaxY div 2),'Laboratornaya rabota 3');
Delay(1000);
RestoreCRTMode;
ClrScr;
TextColor(2);
Write('Vvedite levju granitsy(>-5): ');
ReadLn(x1);
Write('Vvedite pravju granitsy(<5): ');
ReadLn(x2);
Write('Vvedite skoroct k:=0-10 ');
ReadLn(k);
SetGraphMode(GetGraphMode);
SetLineStyle(SolidLn,0,NormWidth);
k:=1000-k*100;
dx:=0.01;
h:=440;
w:=600;
y1:=f(x1);
y2:=f(x2);
If (x1<0) and (x2>0) then
mx:=w/abs(x2-x1) else
If (x1<0) and (x2<0) then
mx:=w/(-x1) else
mx:=w/x2;
If (y1<0) and (y2>0) then
my:=h/abs(y2-y1) else
If (y1<0) and (y2<0) then
my:=h/(-y1) else
my:=h/y2;
If (x1<0) and (x2>0) then
begin
x0:=320-(w div 2)-Round(x1*mx);
y0:=240-(h div 2)+Round(y2*my);
end else
If (x1<0) and (x2<0) then
begin
x0:=620;
y0:=20;
end else
begin
x0:=20;
y0:=460;
end;
Repeat
ClearDevice;
setcolor(3);
line(x0,((480-h) div 2),x0,((480+h) div 2));
line(((640-w) div 2),y0,((640+w) div 2),y0);
setcolor(4);
x:=x1;
while x<=x2 do
begin
y:=f(x);
Putpixel(x0+round(x*mx),y0-round(y*my),4);
x:=x+dx;
end;
SetTextStyle(DefaultFont,HorizDir,1);
SetTextJustify(CenterText,TopText);
SetColor(13);
Str(x1,st);
OutTextXY(x0+round(x1*mx),y0+4,st);
Str(x2,st);
OutTextXY(x0+round(x2*mx),y0+4,st);
SetColor(6);
OutTextXY(100,100,'Grafik y=x^3');
x:=x1;
while x<=x2 do
begin
setcolor(0);
circle(x0+round((x-dx)*mx),y0-round(f(x-dx)*my),8);
setfillstyle(1,0);
floodfill(x0+round((x-dx)*mx),y0-round(f(x-dx)*my),0);
setcolor(4);
setfillstyle(1,1);
circle(x0+round(x*mx),y0-round(f(x)*my),8);
floodfill(x0+round(x*mx),y0-round(f(x)*my),red);
xx:=x1;
xx2:=x;
delay(k);
while xx<=xx2 do
begin
yy:=f(xx);
putpixel(x0+round(xx*mx),y0-round(yy*my),5);
xx:=xx+dx;
end;
setcolor(3);
line(x0,((480-h) div 2),x0,((480+h) div 2));
line(((640-w) div 2),y0,((640+w) div 2),y0);
x:=x+dx;
end;
SetTextStyle(DefaultFont,HorizDir,2);
SetTextJustify(CenterText,CenterText);
OutTextXY(480,360,'Povtorit?(y/n)');
Key:=ReadKey;
Until (Key='n') or (Key='N');
end.
Исправил. А то в предыдущей версии асимметричные интервалы неправильно отрабатывались.
|