From 7be44777d95ba6518d3488922621dc2a112f6796 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Jan 18 2019 18:56:39 +0000 Subject: lazarus: life --- diff --git a/lazarus/life/project1.ico b/lazarus/life/project1.ico new file mode 100644 index 0000000..0341321 Binary files /dev/null and b/lazarus/life/project1.ico differ diff --git a/lazarus/life/project1.lpi b/lazarus/life/project1.lpi new file mode 100644 index 0000000..3afe492 --- /dev/null +++ b/lazarus/life/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/life/project1.lpr b/lazarus/life/project1.lpr new file mode 100644 index 0000000..58c35dc --- /dev/null +++ b/lazarus/life/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/life/project1.res b/lazarus/life/project1.res new file mode 100644 index 0000000..e994dfa Binary files /dev/null and b/lazarus/life/project1.res differ diff --git a/lazarus/life/unit1.lfm b/lazarus/life/unit1.lfm new file mode 100644 index 0000000..12ef9cc --- /dev/null +++ b/lazarus/life/unit1.lfm @@ -0,0 +1,28 @@ +object Form1: TForm1 + Left = 158 + Height = 536 + Top = 196 + Width = 857 + Caption = 'Form1' + ClientHeight = 536 + ClientWidth = 857 + OnMouseDown = FormMouseDown + OnPaint = FormPaint + LCLVersion = '1.6.2.0' + object Button1: TButton + Left = 736 + Height = 25 + Top = 8 + Width = 91 + Caption = 'Start/Stop' + OnClick = Button1Click + TabOrder = 0 + end + object Timer1: TTimer + Enabled = False + Interval = 100 + OnTimer = Timer1Timer + left = 16 + top = 16 + end +end diff --git a/lazarus/life/unit1.pas b/lazarus/life/unit1.pas new file mode 100644 index 0000000..d6dcd07 --- /dev/null +++ b/lazarus/life/unit1.pas @@ -0,0 +1,107 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, + ExtCtrls; + +type + + { TForm1 } + + TForm1 = class(TForm) + Button1: TButton; + Timer1: TTimer; + procedure Button1Click(Sender: TObject); + procedure FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); + procedure FormPaint(Sender: TObject); + procedure Timer1Timer(Sender: TObject); + private + { private declarations } + public + { public declarations } + end; + +const + rows = 20; + cols = 30; + size = 20; +var + Form1: TForm1; + field1, field2: array [0..cols, 0..rows] of boolean; + +implementation + +{$R *.lfm} + +function getCell(x, y: integer): integer; +begin + Result := 0; + x := (x + cols) mod cols; + y := (y + rows) mod rows; + if field1[x, y] then Result := 1; +end; + +procedure TForm1.FormPaint(Sender: TObject); +var + i, j: integer; +begin + Canvas.Brush.Color := clBlack; + for i := 0 to cols-1 do begin + for j := 0 to rows-1 do begin + Canvas.MoveTo(i*size, (j+1)*size); + Canvas.LineTo((i+1)*size, (j+1)*size); + Canvas.LineTo((i+1)*size, j*size); + if field1[i, j] then Canvas.Ellipse(i*size, j*size, (i+1)*size, (j+1)*size); + end; + end; +end; + +procedure TForm1.Button1Click(Sender: TObject); +begin + Timer1.Enabled := not Timer1.Enabled; +end; + +procedure TForm1.Timer1Timer(Sender: TObject); +var + i, j, count: integer; +begin + for i := 0 to cols-1 do begin + for j := 0 to rows-1 do begin + count := 0; + count := count + getCell(i-1, j-1); + count := count + getCell(i-1, j); + count := count + getCell(i-1, j+1); + count := count + getCell(i, j-1); + count := count + getCell(i, j+1); + count := count + getCell(i+1, j-1); + count := count + getCell(i+1, j); + count := count + getCell(i+1, j+1); + if field1[i, j] then begin + field2[i, j] := (count=2) or (count=3); + end else begin + field2[i, j] := count=3; + end; + end; + end; + field1 := field2; + Refresh; +end; + +procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +var + i, j: integer; +begin + i := x div size; + j := y div size; + if (i < cols) and (j < rows) then field1[i, j] := not field1[i, j]; + refresh; +end; + +end. +