unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeEngine, Series, ExtCtrls, StdCtrls, TeeProcs, Chart, ComCtrls, Clipbrd;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    TabSheet4: TTabSheet;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Label3: TLabel;
    Edit3: TEdit;
    GroupBox1: TGroupBox;
    Label4: TLabel;
    Edit4: TEdit;
    Label5: TLabel;
    Edit5: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Chart1: TChart;
    Button1: TButton;
    Button2: TButton;
    Image1: TImage;
    Button3: TButton;
    Button4: TButton;
    Image2: TImage;
    Series1: TLineSeries;
    Label8: TLabel;
    Edit8: TEdit;
    Label9: TLabel;
    Edit9: TEdit;
    Label10: TLabel;
    Edit10: TEdit;
    Label11: TLabel;
    Edit11: TEdit;
    Label12: TLabel;
    Label13: TLabel;
    Edit12: TEdit;
    Edit13: TEdit;
    Button5: TButton;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  xn,xk,x,y,h,xomin,xomax,yomin,yomax : extended;
  m,i,delt: integer;

implementation
function f(x:extended):extended;
begin
  Result:=(x*x/4 + x/2 +1)*exp(x/2);
end;



{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit4.Text:='0';
Edit5.Text:='10';
Edit6.Text:='0';
Edit7.Text:='10';
Edit1.Text:='0,1';
Edit2.Text:='6';
Edit3.Text:='50';

Edit8.Text:='1';
Edit9.Text:='5';
Edit10.Text:='1';
Edit11.Text:='1';
Edit12.Text:='6';
Edit13.Text:='1';

end;

procedure TForm1.Button3Click(Sender: TObject);
var xmax, ymax,xt,yt,yo,xo: integer;
hx,hy: extended;
begin
xn:=StrToFloat(Edit1.Text);
xk:=StrToFloat(Edit2.Text);
m:= StrToInt(Edit3.Text);

xomin:=StrToFloat(Edit4.Text);
xomax:=StrToFloat(Edit5.Text);
yomin:=StrToFloat(Edit6.Text);
yomax:=StrToFloat(Edit7.Text);
Image1.Canvas.Brush.Color:= clWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
with Image1.Canvas do begin
Pen.Color:=clBlack;
Brush.Color:= clGreen;
xmax:=Image1.Width;
ymax:=Image1.Height;

yo:=ymax div 2;
xo:=xmax div 2;
MoveTo(0,yo); LineTo(xmax,yo);
MoveTo(xo,0);  LineTo(xo,ymax);

Pen.Color:=clRed;
Pen.Width:=2;
hx:=(xomax-xomin)/xmax;
hy:=(yomax-yomin)/ymax;

h:=(xk-xn)/(m-1);
x:=xn;
y:=f(x);
MoveTo(Round(x/hx),Round(yo-y/hy));

for i:=1 to m do begin
  x:=x+h;
  y:=f(x);
  LineTo(Round(x/hx),Round(yo-y/hy));
end;
end;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
ClipBoard.Assign(Image1.Picture);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
xn:=StrToFloat(Edit1.Text);
xk:=StrToFloat(Edit2.Text);
m:= StrToInt(Edit3.Text);

xomin:=StrToFloat(Edit4.Text);
xomax:=StrToFloat(Edit5.Text);
yomin:=StrToFloat(Edit6.Text);
yomax:=StrToFloat(Edit7.Text);

with Chart1 do begin
  LeftAxis.Automatic:= False;
  LeftAxis.Minimum:=yomin;
  LeftAxis.Maximum:=yomax;
  BottomAxis.Automatic:=False;
  BottomAxis.Maximum:=xomax;
  BottomAxis.Minimum:=xomin;

  SeriesList[0].Clear;
  h:=(xk-xn)/(m-1); x:=xn;
  for i:=1 to m do begin
    y:=f(x);
    SeriesList[0].AddXY(x,y);
    x:=x+h;
    end;
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Chart1.CopyToClipboardMetafile(True);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
x1,y1,x2,y2,x3,y3,x4,y4,ymax,xmax,yo,xo, width, height, length: integer;
hx,hy, yro, xro,dx,dy,x11,x22,x33,x44,y11,y22,y33,y44:real;
begin

x1:=StrToInt(Edit8.Text);
y1:=StrToInt(Edit9.Text);
x2:=StrToInt(Edit10.Text);
y2:=StrToInt(Edit11.Text);
x3:=StrToInt(Edit12.Text);
y3:=StrToInt(Edit13.Text);

x4:=x3;
y4:=y1;

Label16.Caption:=IntToStr(x4);
Label17.Caption:=IntToStr(y4);

with Image2.Canvas do begin
Brush.Color:=clWhite;
Rectangle(0,0,Image2.Width,Image2.Height);
xo := Image2.Width div 2;
yo := Image2.Height div 2;
Pen.Color:=clBlack;
Pen.Width:=2;
MoveTo(0,yo); LineTo(Image2.Width,yo);
MoveTo(xo,0); LineTo(xo,Image2.Height);

width:= abs(x3-x2);
height:=abs(y1-y2);

hx:=1.5*width/Image2.Width;
hy:=1.5*height/Image2.Height;

x11:=x1/hx+xo;
x22:=x2/hx+xo;
x33:=x3/hx+xo;
x44:=xo+x4/hx;

y11:=yo-y1/hy;
y22:=yo-y2/hy;
y33:=yo-y3/hy;
y44:=yo-y4/hy;

xro:=((x33+x22)/2);
yro:=((y22+y11)/2);

dx:=abs(xro-xo);
dy:=abs(yo-yro);

Rectangle(0,0,Image2.Width,Image2.Height);

MoveTo(0,Round(yo+dy)); LineTo(Image2.Width,Round(yo+dy));
MoveTo(Round(xo-dx),0); LineTo(Round(xo-dx),Image2.Height);

Pen.Color:=clRed;
Pen.Width:=1;

// рисуем прямоугольник
MoveTo(Round((x11-dx)),Round((y11+dy))); LineTo(Round((x22-dx)),Round((y22+dy)));
LineTo(Round((x33-dx)),Round((y33+dy)));
LineTo(Round((x44-dx)),Round((y44+dy)));
LineTo(Round((x11-dx)),Round((y11+dy)));

Label16.Caption:= IntToStr(x4);
Label17.Caption:= IntToStr(y4);


end;


end;

end.
