diff --git a/lazarus/gravity-control/project1.ico b/lazarus/gravity-control/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/gravity-control/project1.ico differ diff --git a/lazarus/gravity-control/project1.lpi b/lazarus/gravity-control/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/gravity-control/project1.lpi @@ -0,0 +1,79 @@ + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + <Icon Value="0"/> + </General> + <i18n> + <EnableI18N LFM="False"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="1"> + <Item1> + <PackageName Value="LCL"/> + </Item1> + </RequiredPackages> + <Units Count="2"> + <Unit0> + <Filename Value="project1.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + </Unit1> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <Target> + <Filename Value="project1"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir)"/> + <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/lazarus/gravity-control/project1.lpr b/lazarus/gravity-control/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/gravity-control/project1.lpr @@ -0,0 +1,21 @@ +program project1; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, Unit1 + { you can add units after this }; + +{$R *.res} + +begin + RequireDerivedFormResource:=True; + Application.Initialize; + Application.CreateForm(TForm1, Form1); + Application.Run; +end. + diff --git a/lazarus/gravity-control/project1.res b/lazarus/gravity-control/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/gravity-control/project1.res differ diff --git a/lazarus/gravity-control/unit1.lfm b/lazarus/gravity-control/unit1.lfm new file mode 100644 index 0000000..f5e71f6 --- /dev/null +++ b/lazarus/gravity-control/unit1.lfm @@ -0,0 +1,31 @@ +object Form1: TForm1 + Cursor = crCross + Left = 167 + Height = 526 + Top = 217 + Width = 830 + Caption = 'Form1' + ClientHeight = 526 + ClientWidth = 830 + OnMouseMove = FormMouseMove + LCLVersion = '1.6.2.0' + object Shape1: TShape + Left = 134 + Height = 65 + Top = 123 + Width = 65 + Shape = stCircle + end + object Timer1: TTimer + Interval = 5 + OnTimer = Timer1Timer + left = 17 + top = 10 + end + object Timer2: TTimer + Interval = 50 + OnTimer = Timer2Timer + left = 56 + top = 9 + end +end diff --git a/lazarus/gravity-control/unit1.pas b/lazarus/gravity-control/unit1.pas new file mode 100644 index 0000000..40b8a27 --- /dev/null +++ b/lazarus/gravity-control/unit1.pas @@ -0,0 +1,86 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls; + +type + + { TForm1 } + + TForm1 = class(TForm) + Shape1: TShape; + Timer1: TTimer; + Timer2: TTimer; + procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); + procedure Timer1Timer(Sender: TObject); + procedure Timer2Timer(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +const + G = 1000000; + +var + Form1: TForm1; + mx: double = 0; + my: double = 0; + x: double = 200; + y: double = 200; + vx: double = 0; + vy: double = 0; + +implementation + +{$R *.lfm} + +procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, + Y: Integer); +begin + mx := x; + my := y; +end; + +procedure TForm1.Timer1Timer(Sender: TObject); +var + dx, dy, d: double; + ax, ay: double; + t, r: double; +begin + dx := mx - x; + dy := my - y; + d := sqrt(dx*dx + dy*dy); + t := Timer1.Interval/1000; + r := Shape1.Width/2; + + ax := G*dx/(d*d*d); + ay := G*dy/(d*d*d); + + if d < 10 then begin ax:=0; ay:=0; end; + + vx := vx + ax*t; + vy := vy + ay*t; + + x := x + vx*t; + y := y + vy*t; + + if x < r then begin x:=r; vx:=abs(vx); end; + if x > ClientWidth-r then begin x:=ClientWidth-r; vx:=-abs(vx); end; + if y < r then begin y:=r; vy:=abs(vy); end; + if y > ClientHeight-r then begin y:=ClientHeight-r; vy:=-abs(vy); end; +end; + +procedure TForm1.Timer2Timer(Sender: TObject); +begin + Shape1.Left := round(x - Shape1.Width/2); + Shape1.Top := round(y - Shape1.Height/2); +end; + +end. +