From c1147629f7aae2ee90ccd7c9f1ccbf106361d486 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 13 Dec 2025 16:35:46 +0100 Subject: =?UTF-8?q?Add=20book=20"=D0=97=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1/4_gas/gas.ico" | Bin 0 -> 137040 bytes .../1/4_gas/gas.lpi" | 78 +++++++++ .../1/4_gas/gas.lpr" | 22 +++ .../1/4_gas/gas.lps" | 39 +++++ .../1/4_gas/gas.res" | Bin 0 -> 139052 bytes .../1/4_gas/unit1.lfm" | 43 +++++ .../1/4_gas/unit1.pas" | 181 +++++++++++++++++++++ 7 files changed, 363 insertions(+) create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.ico" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpi" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpr" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lps" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.res" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.lfm" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.pas" (limited to 'Занимательное программирование/1/4_gas') diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.ico" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.ico" new file mode 100644 index 0000000..0341321 Binary files /dev/null and "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.ico" differ diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpi" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpi" new file mode 100644 index 0000000..9ae4d18 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpi" @@ -0,0 +1,78 @@ + + + + + + + + + <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="gas.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="gas"/> + </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/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpr" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpr" new file mode 100644 index 0000000..a84765a --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lpr" @@ -0,0 +1,22 @@ +program gas; + +{$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. + diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lps" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lps" new file mode 100644 index 0000000..bf37068 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.lps" @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<CONFIG> + <ProjectSession> + <Version Value="11"/> + <BuildModes Active="Default"/> + <Units Count="2"> + <Unit0> + <Filename Value="gas.lpr"/> + <IsPartOfProject Value="True"/> + <EditorIndex Value="-1"/> + <WindowIndex Value="-1"/> + <TopLine Value="-1"/> + <CursorPos X="-1" Y="-1"/> + <UsageCount Value="35"/> + </Unit0> + <Unit1> + <Filename Value="unit1.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="Form1"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="Unit1"/> + <IsVisibleTab Value="True"/> + <EditorIndex Value="-1"/> + <TopLine Value="115"/> + <CursorPos X="21" Y="169"/> + <UsageCount Value="35"/> + </Unit1> + </Units> + <General> + <ActiveWindowIndexAtStart Value="-1"/> + </General> + <JumpHistory HistoryIndex="-1"/> + <RunParams> + <FormatVersion Value="2"/> + <Modes Count="0" ActiveMode=""/> + </RunParams> + </ProjectSession> +</CONFIG> diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.res" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.res" new file mode 100644 index 0000000..1adb040 Binary files /dev/null and "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/gas.res" differ diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.lfm" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.lfm" new file mode 100644 index 0000000..ffe21cd --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.lfm" @@ -0,0 +1,43 @@ +object Form1: TForm1 + Left = 1198 + Height = 684 + Top = 326 + Width = 732 + Caption = 'Form1' + ClientHeight = 684 + ClientWidth = 732 + DesignTimePPI = 93 + LCLVersion = '2.0.12.0' + object StartStopBtn: TButton + Left = 296 + Height = 27 + Top = 512 + Width = 140 + Caption = 'Пуск' + OnClick = StartStopBtnClick + TabOrder = 0 + end + object Screen: TPaintBox + Left = 16 + Height = 416 + Top = 15 + Width = 702 + OnPaint = ScreenPaint + end + object Cold: TLabel + Left = 144 + Height = 16 + Top = 448 + Width = 7 + Caption = '0' + ParentColor = False + end + object Warm: TLabel + Left = 528 + Height = 16 + Top = 448 + Width = 7 + Caption = '0' + ParentColor = False + end +end diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.pas" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.pas" new file mode 100644 index 0000000..22a8433 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/4_gas/unit1.pas" @@ -0,0 +1,181 @@ +unit Unit1; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls, + Math; + +type + + Molecule = record + X, Y: Integer; + Vx, Vy: Integer; + end; + + { TForm1 } + + TForm1 = class(TForm) + Cold: TLabel; + Warm: TLabel; + StartStopBtn: TButton; + Screen: TPaintBox; + procedure ScreenPaint(Sender: TObject); + procedure StartStopBtnClick(Sender: TObject); + private + + public + + end; + +var + Form1: TForm1; + IsRunning: Boolean = false; + +implementation + +{$R *.lfm} + +procedure TForm1.ScreenPaint(Sender: TObject); +begin + +end; + +procedure TForm1.StartStopBtnClick(Sender: TObject); + const RMolecule: Integer = 10; { Радиус молекулы } + const RHole: Integer = 15; + const V: Integer = 7; { Скорость молекулы } + const N = 20; { Количество молекул } + + var angle: Real; { Угол, задающий начальное направление полета } + i: Integer; { Счетчик цикла } + Mol: array[1..N * 2] of Molecule; { Массив молекул } + CurV: Integer; { Выбранаая случайная скорость молекулы } + halfScreen: Integer; + T1, T2: Integer; { Температуры и количество, статистика } + +begin + if IsRunning then + begin + IsRunning := false; + StartStopBtn.Caption := 'Пуск'; + Exit; + end; + + StartStopBtn.Caption := 'Стоп'; + IsRunning := true; + + Randomize; + Screen.Refresh; + + halfScreen := Screen.Width div 2; + T1 := V * N; + T2 := V * N; + + for i := 1 to N * 2 do { Цикл по все молекулам } + begin + { Выбор начального положения молекулы } + if i <= N then + begin + Mol[i].X := RandomRange(RMolecule, halfScreen - RMolecule); + end + else + begin + Mol[i].X := RandomRange(halfScreen + RMolecule, + Screen.Width - RMolecule); + end; + Mol[i].Y := RandomRange(RMolecule, Screen.Height - RMolecule); + + { Выбор нправления и скорости молекулы (1 - V) } + angle := Random(360) * Pi / 180; + CurV := RandomRange(1, V); + Mol[i].Vx := Round(CurV * Sin(angle)); { Получение составляющих } + Mol[i].Vy := Round(CurV * Cos(angle)); { скорости молекулы } + end; + + while IsRunning do { Основной цикл } + begin + { Черчение перегородки } + Screen.Canvas.Line(halfScreen, 0, halfScreen, + Screen.Height div 2 - RHole - RMolecule); + Screen.Canvas.Line(halfScreen, Screen.Height div 2 + RHole + RMolecule, + halfScreen, Screen.Height); + + for i := 1 to N * 2 do { Цикл по всем молекулам } + begin + Screen.Canvas.Pen.Color := clBtnFace; + Screen.Canvas.Ellipse(Mol[i].X - RMolecule, Mol[i].Y - RMolecule, + Mol[i].X + RMolecule, Mol[i].Y + RMolecule); + + { Сдвигаем на новую позицию } + Mol[i].X := Mol[i].X + Mol[i].Vx; + Mol[i].Y := Mol[i].Y + Mol[i].Vy; + + if (Mol[i].X > halfScreen - RMolecule) and + (Mol[i].X - Mol[i].Vx <= halfScreen - RMolecule) then + begin + if (Mol[i].Y >= Screen.Height div 2 - RHole) and + (Mol[i].Y <= Screen.Height div 2 + RHole) then + begin + T1 := T1 - V; T2 := T2 + V; + end + else + begin + Mol[i].X := halfScreen - RMolecule; + Mol[i].Vx := -Mol[i].Vx; + end; + end + else if (Mol[i].X < halfScreen + RMolecule) and + (Mol[i].X - Mol[i].Vx >= halfScreen + RMolecule) then + begin + if (Mol[i].Y >= Screen.Height div 2 - RHole) and + (Mol[i].Y <= Screen.Height div 2 + RHole) then + begin + T2 := T2 - V; + T1 := T1 + V; + end + else + begin + Mol[i].X := halfScreen + RMolecule; + Mol[i].Vx := -Mol[i].Vx; + end; + end; + + { Определяем, не вышла ли молекула за границы аквариума } + if Mol[i].X > Screen.Width - RMolecule then + begin + Mol[i].X := Screen.Width - RMolecule; + Mol[i].Vx := -Mol[i].Vx; + end; + if Mol[i].X < RMolecule then + begin + Mol[i].X := RMolecule; + Mol[i].Vx := -Mol[i].Vx; + end; + if Mol[i].Y > Screen.Height - RMolecule then + begin + Mol[i].Y := Screen.Height - RMolecule; + Mol[i].Vy := -Mol[i].Vy; + end; + if Mol[i].Y < RMolecule then + begin + Mol[i].Y := RMolecule; + Mol[i].Vy := -Mol[i].Vy; + end; + + Cold.Caption := IntToStr(T1); + Warm.Caption := IntToStr(T2); + + Screen.Canvas.Pen.Color := clBlue; { Рисуем молекулу на новой } + Screen.Canvas.Ellipse(Mol[i].X - RMolecule, Mol[i].Y - RMolecule, { позиции } + Mol[i].X + RMolecule, Mol[i].Y + RMolecule); + end; + Sleep(10); { Пауза на 10 миллисекунд } + Application.ProcessMessages; + end; +end; + +end. + -- cgit v1.2.3