Графік функції
Код мовою Pascal
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, jpeg;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Image1: TImage;
procedure PaintBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function f(x:real):real;
begin
f:=exp(x);
end;
procedure TForm1.PaintBox1Click(Sender: TObject);
var x,y,xp,xk:real;
i,sx,sy:integer;
begin
sx:=160;
sy:=360;
xp:=-9;
xk:=9;
PaintBox1.Canvas.Pen.Color:=clGray;
for i := 0 to 9 do begin
PaintBox1.Canvas.MoveTo(i*40,0);
PaintBox1.Canvas.LineTo(i*40,400);
end;
for i := 0 to 9 do begin
PaintBox1.Canvas.MoveTo(0,i*40);
PaintBox1.Canvas.LineTo(400,i*40);
end;
PaintBox1.Canvas.Pen.Color:=clBlack;
PaintBox1.Canvas.Pen.Width:=3;
//
PaintBox1.Canvas.MoveTo(sx-1,0);
PaintBox1.Canvas.LineTo(sx-1,400);
//
PaintBox1.Canvas.MoveTo(0,sy-1);
PaintBox1.Canvas.LineTo(400,sy-1);
//
PaintBox1.Canvas.MoveTo(sx-6,10);
PaintBox1.Canvas.LineTo(sx-1,0);
PaintBox1.Canvas.MoveTo(sx+4,10);
PaintBox1.Canvas.LineTo(sx-1,0);
//
PaintBox1.Canvas.MoveTo(390,sy-5);
PaintBox1.Canvas.LineTo(400,sy-1);
PaintBox1.Canvas.MoveTo(390,sy+4);
PaintBox1.Canvas.LineTo(400,sy-1);
PaintBox1.Canvas.Font.Size :=12;
PaintBox1.Canvas.TextOut(sx-15,10,'Y');
PaintBox1.Canvas.TextOut(sx-15,10+sy-60,'1');
PaintBox1.Canvas.TextOut(sx-15,sy+3,'0');
PaintBox1.Canvas.TextOut(sx+36,sy+3,'1');
PaintBox1.Canvas.TextOut(380,sy+3,'X');
PaintBox1.Canvas.Pen.Color:=clRed;
PaintBox1.Canvas.Pen.Width:=2;
PaintBox1.Canvas.MoveTo(round(40*xp+sx),round(sy-40*f(xp)));
x:=xp;
while x<xk do begin
y:=f(x);
PaintBox1.Canvas.LineTo(round(40*x+sx),round(sy-40*y));
x:=x+0.1;
end;
end;
end.
Немає коментарів:
Дописати коментар