Thema: Delphi Gasteilchen-Simulation

Einzelnen Beitrag anzeigen

xy124

Registriert seit: 3. Dez 2007
146 Beiträge
 
Delphi 7 Personal
 
#11

Re: Gasteilchen-Simulation

  Alt 11. Feb 2008, 17:47
ich habs geschrieben!

erstell nen Timer nen shape und nen button!

dan so:
(musst auch noch timer und button doppelklicken, evtl timerintervall verringern dann alles reinkopieren!...)
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, math;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Button1: TButton;
    Timer1: TTimer;
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  x, y: Integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  timer1.enabled := true;
  x := 5; //Startwerte für X&Y-Speed
  y := 3;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  //Kollissionstests
  if (shape1.Top < 0) or (shape1.Top > clientheight - shape1.Height) then
    y := -y;
  if (shape1.Left < 0) or (shape1.Left > clientwidth - shape1.width) then
    x := -x;
  
  //eigentliche bewegung
  shape1.Top := shape1.Top + y;
  shape1.Left := shape1.Left + x;

  form1.caption := floattostr(sqrt(x*x+y*Y)) //pythagoras(schreibt man den so?) hilft weiter
end;
end.
was war jetzt so schwer daran?
  Mit Zitat antworten Zitat