unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, StdCtrls, Buttons, Math, ShellApi;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Vysledky2: TGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    Kmity_freq: TLabel;
    Kmity_delta: TLabel;
    Tl1Vykresli_K: TBitBtn;
    Tl3Napoveda_K: TBitBtn;
    Tl2Smaz_K: TBitBtn;
    Parametry2: TGroupBox;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label9: TLabel;
    Label13: TLabel;
    Tuhost: TEdit;
    Hmotnost: TEdit;
    Odpor: TEdit;
    Rychlost: TEdit;
    Vychylka: TEdit;
    Plocha2: TImage;
    procedure FormCreate(Sender: TObject);

    procedure Tl1Vykresli_KClick(Sender: TObject);
    procedure Tl2Smaz_KClick(Sender: TObject);



  private
     t, dt, vy,y,y0,a,b,m,k:real;

    { Private declarations }
  public
{ Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
    try
  Plocha2.Picture.LoadFromFile('kmity.bmp');     // Po startu nactu pozadi,
  except                                         // na nez se bude kreslit
  showmessage('Nemohu nalézt soubor kmity.bmp'); close
  end;

end;



procedure TForm1.Tl1Vykresli_KClick(Sender: TObject);
var v0,vy:real;


Code1,code2,code3,code4,Code5:integer;
begin
 if (Hmotnost.Text <> '') and (Tuhost.Text <> '')
 and (Odpor.Text <> '') and (Rychlost.Text <> '')
 and (Vychylka.Text <> '')then
         begin
            Val(Hmotnost.Text, m, Code1);   // prevedu text na cisla
            Val(Tuhost.Text, k, Code2);
            Val(Odpor.Text, b, Code3);
            Val(Rychlost.Text, v0, Code4);
            Val(Vychylka.Text, y0, Code5)
         end

      else

         begin
            Application.MessageBox('Vyplňte všechny vstupní údaje!','Chyba zadání!',MB_ICONERROR);
            exit
         end;


  if (Code1 <> 0) or (Code2 <> 0) or (Code3 <> 0)
  or (Code4 <> 0) or (Code5 <> 0)then
          begin
             Application.MessageBox('Vyplňujte číselné údaje...','Chyba zadání!',MB_ICONERROR);
             exit
          end;
     Plocha2.Canvas.MoveTo(20,150-trunc(y0*160));
     Timer1.Enabled:=True;

        Kmity_delta.Caption:=FloatToStr(SimpleRoundTo(b/(2*m),-4));
     Kmity_freq.Caption:=FloatToStr(SimpleRoundTo(sqrt(k/m),-4))+' Hz';

 y:=y0;  vy:=v0/1000;



   


  t:=0;
  dt:=0.1;

repeat
   t:=t+dt;
     y:=0.07+y+vy*dt;


     a:=-b/2/m*vy-k/m*y;
     vy:=vy+a*dt;


    Plocha2.Canvas.LineTo(20+trunc(10*t),160-trunc(y0*160)-trunc(y*160));
    Kmity_freq.Caption:=FloatToStr(SimpleRoundTo(y0,-4));

    until   t*10>600
end;



procedure TForm1.Tl2Smaz_KClick(Sender: TObject);
begin
Timer1.Enabled:=False;
  Plocha2.Picture.LoadFromFile('kmity.bmp');
end;

end.
