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,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="Ideal gas"/>
<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"/>
<Modes Count="0"/>
</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>

View File

@@ -0,0 +1,23 @@
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.Title:='Ideal gas';
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="2">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="20"/>
</Unit0>
<Unit1>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
<IsVisibleTab Value="True"/>
<CursorPos Y="45"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="3" HistoryIndex="2">
<Position1>
<Filename Value="unit1.pas"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="16" Column="15"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="48" Column="5"/>
</Position3>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,27 @@
object Form1: TForm1
Left = 976
Height = 506
Top = 800
Width = 767
Caption = 'Form1'
ClientHeight = 506
ClientWidth = 767
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object Screen: TPaintBox
Left = 11
Height = 432
Top = 11
Width = 740
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 336
Height = 20
Top = 464
Width = 99
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
end

View File

@@ -0,0 +1,125 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
Math;
type
Molecule = record
X, Y: Integer;
Vx, Vy: Integer;
end;
{ TForm1 }
TForm1 = class(TForm)
StartStopBtn: TButton;
Screen: TPaintBox;
procedure StartStopBtnClick(Sender: TObject);
procedure ScreenPaint(Sender: TObject);
private
const R: Integer = 10; { Радиус молекулы }
V: Integer = 7; { Максимальная скорость молекулы }
N = 30; { Количество молекул }
var Mol: array[1..N] of Molecule; { Массив молекул }
public
end;
var
Form1: TForm1;
IsRunning: Boolean = false;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.ScreenPaint(Sender: TObject);
var i: Integer;
begin
if not IsRunning then Exit;
for i := 1 to N do { Цикл по всем молекулам }
begin
Screen.Canvas.Pen.Color := clBtnFace; { Стираем молекулу }
Screen.Canvas.Ellipse(Mol[i].X - R, Mol[i].Y - R,
Mol[i].X + R, Mol[i].Y + R);
Mol[i].X := Mol[i].X + Mol[i].Vx; { Сдвигаем на новую позицию }
Mol[i].Y := Mol[i].Y + Mol[i]. Vy;
{ Определяем, не вышла ли молекула за границы аквариума }
if Mol[i].X > Screen.Width - R then
begin
Mol[i].X := Screen.Width - R;
Mol[i].Vx := -Mol[i].Vx;
end;
if Mol[i].X < R then
begin
Mol[i].X := R;
Mol[i].Vx := -Mol[i].Vx;
end;
if Mol[i].Y > Screen.Height - R then
begin
Mol[i].Y := Screen.Height - R;
Mol[i].Vy := -Mol[i].Vy;
end;
if Mol[i].Y < R then
begin
Mol[i].Y := R;
Mol[i].Vy := -Mol[i].Vy;
end;
Screen.Canvas.Pen.Color := clBlue; { Рисуем молекулу на новой }
Screen.Canvas.Ellipse(Mol[i].X - R, Mol[i].Y - R, { позиции }
Mol[i].X + R, Mol[i].Y + R);
end;
end;
procedure TForm1.StartStopBtnClick(Sender: TObject);
var angle: Real; { Угол, задающий изначальное направление полета }
i: Integer; { Счетчик цикла }
CurV: Integer; { Выбранная случайная скорость молекулы }
begin
if IsRunning then
begin
IsRunning := false;
StartStopBtn.Caption := 'Пуск';
Exit;
end;
StartStopBtn.Caption := 'Стоп';
IsRunning := true;
Randomize;
for i := 1 to N do { Цикл по всем молекулам }
begin
Mol[i].X := RandomRange(R, Screen.Width - R); { Выбор начального }
Mol[i].Y := RandomRange(R, Screen.Height - R); { положения молекулы }
angle := Random(360) * Pi / 180; { и ее направления }
CurV := RandomRange(1, V); { Выбор скорости молекулы (1 - V) }
Mol[i].Vx := Round(CurV * Sin(angle)); { Получение составляющих }
Mol[i].Vy := Round(CurV * Cos(angle)); { скорости молекулы }
end;
while IsRunning do { Основной цикл }
begin
Screen.Invalidate;
Sleep(10); { Пауза на 10 миллисекунд }
Application.ProcessMessages;
if Application.Terminated then Break;
end;
end;
end.