unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls,ftdata,unit3;
type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    procedure formresize(Sender: TObject);
    procedure PaintBox1Paint(Sender: TObject);
    procedure FormClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
    
    Calc:boolean;
    procedure ShowGraph;
    procedure Analyse;
    procedure FillGraph;
    procedure CalcStep;
    procedure Idle(Sender: TObject; var Done: Boolean);

  end;

var
  Form1: TForm1;
  {var MyThreadId:integer;
  function MYthread(Parameter: Pointer): Integer;}
implementation


{$R *.DFM}


{function MYthread(Parameter: Pointer): Integer;
begin
with TForm1(Parameter) do begin
 while Calc do begin
 ShowGraph;
 CalcStep;
 end;
end;
end;}
procedure TForm1.formresize(Sender: TObject);
begin
width:=650;
end;
procedure Tform1.ShowGraph;
var n,ly,cy:longint;
begin

 cy:=
 paintbox1.height div 2;

 for n:=0 to MaxGrX do with paintbox1.canvas do
 begin
  pen.color:=clWhite;
  moveto(n,0);
  lineto(n,paintbox1.height);
  {pixels[n,cy]:=clGreen;}
  pixels[n,cy-round(paintbox1.height/2*graph[n])]:=clBlack;
 end;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
if not calc then ShowGraph;
end;
procedure Tform1.Analyse;
var n,x:longint;alpha:real;
begin
a:=0;
 for n:=1 to MaxC do begin
  table[n]:=0;
  phases[n]:=0;
  for x:=0 to MaxGrX do begin
   alpha:=x*pi/maxgrx;
   table[n]:=table[n]+sin(alpha*(n))*graph[x];
  end;
  table[n]:=table[n]*2{da}/maxgrx;
 end;
form3.redraw;
form3dup.redraw;
end;
procedure TForm1.FillGraph;
var x:longint;
begin
 {for x:=0 to 100 do graph[x]:=0.5;}
 for x:=0 to MaxGrX do graph[x]:=0;
end;
procedure Tform1.CalcStep;
var n,x:longint;alpha:single;
begin
 a:=a+da;
 for x:=0 to MaxGrX do begin
  graph[x]:=0;
  alpha:=x*pi/maxgrx;
  for n:=1 to MaxC do begin
   graph[x]:=graph[x]+sin(alpha*(n))*table[n]*cos(a*(n)+phases[n]);
  end;

 end;
end;
procedure TForm1.FormClick(Sender: TObject);
begin

{repeat  }
ShowGraph;
{Sleep(10);}
{until false; }
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FillGraph;
Analyse;
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var n,en:longint;
begin
if x<0 then x:=0 else if x>MaxGrX then x:=MaxGrX;
en:=x+10;
if en>=maxGrX then en:=MaxGrX;

for n:=x to en do graph[n]:=(paintBox1.height div 2- y)*2/paintBox1.height;
ShowGraph;
Analyse;
end;
procedure Tform1.Idle(Sender: TObject; var Done: Boolean);
begin
done:=not calc;
if calc then begin
CalcStep;
ShowGraph;
end;
end;
procedure TForm1.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
{PaintBox1MouseDown(sender,mbLeft,shift,x,y); }
end;

end.
