unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Image1: TImage;
    Chart1: TChart;
    Series1: TLineSeries;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

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

implementation

{$R *.dfm}

function f(x:extended):extended;
begin
  f:=exp(x*cos(Pi/4))*cos(x*sin(Pi/4));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.Text:='0,1';
  Edit2.Text:='10';
  Edit3.Text:='100';
  Edit4.Text:='0';
  Edit5.Text:='-50';
  Edit6.Text:='50';
  Edit7.Text:='50';
  xn:=StrToFloat(Edit1.Text);
  xk:=StrToFloat(Edit2.Text);
  m:=StrToInt(Edit3.Text);
  xomin:=StrToFloat(Edit4.Text);
  xomax:=StrToFloat(Edit6.Text);
  yomin:=StrToFloat(Edit5.Text);
  yomax:=StrToFloat(Edit7.Text);
  with Chart1 do
  begin
   LeftAxis.Automatic:=False;
   LeftAxis.Minimum:=yomin;
   LeftAxis.Maximum:=yomax;
   BottomAxis.Automatic:=False;
   BottomAxis.Minimum:=xomin;
   BottomAxis.Maximum:=xomax;
   SeriesList[0].Clear;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  xmax,ymax,xt,yt,yo:integer;
  hx,hy:extended;

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

    yo:=ymax div 2;
    MoveTo(0,yo);
    LineTo(xmax,yo);
    MoveTo(0,0);
    LineTo(0,ymax);
    Pen.Color:=clRed;
    Pen.Width:=2;
    hx:=(xomax-xomin)/xmax;
    hy:=(yomax-yomin)/ymax;

    h:=abs(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.Button2Click(Sender: TObject);
begin
  ClipBoard.Assign(Image1.Picture);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  xn:=StrToFloat(Edit1.Text);
  xk:=StrToFloat(Edit2.Text);
  m:=StrToInt(Edit3.Text);
  xomin:=StrToFloat(Edit4.Text);
  xomax:=StrToFloat(Edit6.Text);
  yomin:=StrToFloat(Edit5.Text);
  yomax:=StrToFloat(Edit7.Text);

  with Chart1 do
  begin
    LeftAxis.Automatic:=False;
    LeftAxis.Minimum:=yomin;
    LeftAxis.Maximum:=yomax;
    BottomAxis.Automatic:=False;
    BottomAxis.Minimum:=xomin;
    BottomAxis.Maximum:=xomax;
    SeriesList[0].Clear;
    h:=abs(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.Button4Click(Sender: TObject);
begin
  Chart1.CopyToClipboardMetafile(True);
end;

end.
