Add book "Занимательное программирование"

This commit is contained in:
2025-12-13 16:35:46 +01:00
parent 98329e0a3d
commit c1147629f7
78 changed files with 4530 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<CompatibilityMode Value="True"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="conway"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
<Icon Value="0"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages Count="1">
<Item1>
<PackageName Value="LCL"/>
</Item1>
</RequiredPackages>
<Units Count="2">
<Unit0>
<Filename Value="conway.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="conway"/>
</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>

View File

@@ -0,0 +1,22 @@
program conway;
{$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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units Count="2">
<Unit0>
<Filename Value="conway.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="22"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<IsVisibleTab Value="True"/>
<TopLine Value="28"/>
<CursorPos X="26" Y="17"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="3" HistoryIndex="2">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="132" Column="29" TopLine="101"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="17" Column="26"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="132" Column="29" TopLine="95"/>
</Position3>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,26 @@
object Form1: TForm1
Left = 973
Height = 501
Top = 519
Width = 807
Caption = 'Form1'
ClientHeight = 501
ClientWidth = 807
LCLVersion = '2.2.2.0'
object Screen: TPaintBox
Left = 7
Height = 431
Top = 9
Width = 792
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 372
Height = 26
Top = 462
Width = 74
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
end

View File

@@ -0,0 +1,148 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
StartStopBtn: TButton;
Screen: TPaintBox;
procedure ScreenPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
private
const FieldWidth = 30;
FieldHeight = 25;
var Field: array [0 .. FieldWidth + 1, 0 .. FieldHeight + 1] of Boolean;
Changes: array [0 .. FieldWidth + 1, 0 .. FieldHeight + 1] of Boolean;
Rx, Ry: Integer;
public
end;
var
Form1: TForm1;
IsRunning: Boolean;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
var x, y, offset: Integer;
s, i, j: Integer;
u, v: Integer;
begin
if IsRunning then
begin
IsRunning := false;
StartStopBtn.Caption := 'Пуск';
Exit;
end;
StartStopBtn.Caption := 'Стоп';
IsRunning := true;
Rx := (Screen.Width div FieldWidth) div 2;
Ry := (Screen.Height div FieldHeight) div 2;
{ Очистка поля }
for i := 0 to FieldWidth + 1 do
for j := 0 to FieldHeight + 1 do
begin
Field[i, j] := false;
Changes[i, j] := false;
end;
{ Здесь внести строки, задающие конфигурацию инфузорий }
offset := 1;
Field[offset + 0, 10] := true;
Field[offset + 1, 10] := true;
Field[offset + 2, 9] := true;
Field[offset + 2, 11] := true;
Field[offset + 3, 10] := true;
Field[offset + 4, 10] := true;
Field[offset + 5, 10] := true;
Field[offset + 6, 10] := true;
Field[offset + 7, 9] := true;
Field[offset + 7, 11] := true;
Field[offset + 8, 10] := true;
Field[offset + 9, 10] := true;
while IsRunning do
begin
Screen.Invalidate;
for x := 1 to FieldWidth do
for y := 1 to FieldHeight do
begin
s := 0;
for i := -1 to 1 do
for j := -1 to 1 do
begin
if (x = 1) and (i = -1) then
u := FieldWidth - 1
else if (x = FieldWidth - 1) and (i = 1) then
u := 1
else
u := x;
if (y = 1) and (j = -1) then
v := FieldHeight - 1
else if (y = FieldHeight - 1) and (y = 1) then
v := 1
else
v := y;
s := s + Ord(Field[u + i][v + j]);
end;
s := s - Ord(Field[x][y]);
{ Если произошло рождение или смерть }
if ((Field[x, y] = false) and (s = 3)) or
((Field[x, y] = true) and ((s < 2) or (s > 3))) then
Changes[x, y] := true;
end;
{ Внесение изменений }
for x := 1 to FieldWidth do
for y := 1 to FieldHeight do
begin
if Changes[x, y] then
begin
Field[x, y] := not Field[x, y]; { Меняем состояние на }
Changes[x, y] := false; { противоположное }
end;
end;
Sleep(100);
Application.ProcessMessages;
if Application.Terminated then
IsRunning := false;
end;
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var i, j: Integer;
begin
for i := 1 to FieldWidth do
for j := 1 to FieldHeight do
begin
if Field[i, j] then
Screen.Canvas.Pen.Color := clBlue
else
Screen.Canvas.Pen.Color := clBtnFace;
Screen.Canvas.Ellipse((2 * i - 1) * Rx - Rx, (2 * j - 1) * Ry - Ry,
(2 * i - 1) * Rx + Rx, (2 * j - 1) * Ry + Ry);
end;
end;
end.