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

View File

@@ -15,3 +15,7 @@ Von Markus Neumann.
## Haskell Programming from first principles
By Christopher Allen and Julie Moronuki.
## Занимательное программирование
Максим Мозговой.

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="project1"/>
<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="project1.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="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,22 @@
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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units Count="2">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<CursorPos X="22" Y="10"/>
<UsageCount Value="31"/>
</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="42"/>
<CursorPos X="16" Y="53"/>
<UsageCount Value="31"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="53" TopLine="38"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="60" TopLine="38"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="75" TopLine="38"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="50" TopLine="38"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="53" TopLine="38"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="60" TopLine="38"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="75" TopLine="38"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="50" TopLine="38"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="53" TopLine="38"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="60" TopLine="38"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="75" TopLine="38"/>
</Position11>
<Position12>
<Filename Value="unit1.pas"/>
<Caret Line="50" TopLine="38"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="53" TopLine="38"/>
</Position13>
<Position14>
<Filename Value="unit1.pas"/>
<Caret Line="60" TopLine="38"/>
</Position14>
<Position15>
<Filename Value="unit1.pas"/>
<Caret Line="75" TopLine="38"/>
</Position15>
<Position16>
<Filename Value="unit1.pas"/>
<Caret Line="70" Column="16" TopLine="51"/>
</Position16>
<Position17>
<Filename Value="unit1.pas"/>
<Caret Line="50" Column="36" TopLine="36"/>
</Position17>
<Position18>
<Filename Value="unit1.pas"/>
<Caret Line="49" Column="20" TopLine="27"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="68" Column="8" TopLine="49"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="66" TopLine="49"/>
</Position20>
<Position21>
<Filename Value="unit1.pas"/>
<Caret Line="70" TopLine="49"/>
</Position21>
<Position22>
<Filename Value="unit1.pas"/>
<Caret Line="66" TopLine="49"/>
</Position22>
<Position23>
<Filename Value="unit1.pas"/>
<Caret Line="70" TopLine="49"/>
</Position23>
<Position24>
<Filename Value="unit1.pas"/>
<Caret Line="66" TopLine="49"/>
</Position24>
<Position25>
<Filename Value="unit1.pas"/>
<Caret Line="100" Column="36" TopLine="67"/>
</Position25>
<Position26>
<Filename Value="unit1.pas"/>
<Caret Line="81" Column="32" TopLine="45"/>
</Position26>
<Position27>
<Filename Value="unit1.pas"/>
<Caret Line="72" Column="17" TopLine="47"/>
</Position27>
<Position28>
<Filename Value="unit1.pas"/>
<Caret Line="61" Column="6" TopLine="45"/>
</Position28>
<Position29>
<Filename Value="unit1.pas"/>
<Caret Line="62" Column="16" TopLine="46"/>
</Position29>
<Position30>
<Filename Value="unit1.pas"/>
<Caret Line="64" Column="9" TopLine="40"/>
</Position30>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,35 @@
object Form1: TForm1
Left = 1507
Height = 973
Top = 251
Width = 1014
Caption = 'Form1'
ClientHeight = 973
ClientWidth = 1014
LCLVersion = '2.2.2.0'
object Screen: TPaintBox
Left = 8
Height = 760
Top = 8
Width = 960
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 448
Height = 31
Top = 784
Width = 86
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
object EditK: TEdit
Left = 336
Height = 32
Top = 784
Width = 80
NumbersOnly = True
TabOrder = 1
Text = '2'
end
end

View File

@@ -0,0 +1,139 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
type
{ Драконова ломаная
Чтобы ее нарисовать мы начинае с одного отрезка. Одна из точек этого
отрезка это точка сгиба. Чтобы "разогнуть" этот отрезок нам нужно
нарисовать все что находится по одну сторону от точки сгиба
на другой стороне, но под углом в 90 градусов.
}
{ TForm1 }
TForm1 = class(TForm)
EditK: TEdit;
StartStopBtn: TButton;
Screen: TPaintBox;
procedure ScreenPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
private
var x, y: Integer; { Положение "черепашки" }
angle: Real; { и ее направление }
pen: Boolean; { Режим работы (рисовать/не рисовать) }
turns: array of Real;
public
procedure TURTLE_INIT; { Инициализация }
procedure GO(distance: Integer); { Пройти distance пикселов по прямой }
procedure TURN(a: Real); { Повернуться на угол a }
procedure PEN_UP; { Поднять карандаш (не рисовать) }
procedure PEN_DOWN; { Опустить карандаш (рисовать) }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.StartStopBtnClick(Sender: TObject);
var
i, oldIndex, oldSize, newSize, k, j: Integer;
begin
{ Длина массива 2 ^ (k - 1) }
oldSize := 1;
// k = 1
turns := [0];
k := StrToInt(EditK.Text);
if k > 1 then
begin
for j := 2 to k do
begin
newSize := oldSize * 2;
SetLength(turns, newSize);
oldIndex := oldSize - 1;
turns[oldSize] := -90;
for i := oldSize + 1 to newSize - 1 do
begin
turns[i] := -turns[oldIndex];
oldIndex := oldIndex - 1;
end;
oldSize := newSize;
end;
end;
Screen.Invalidate;
Sleep(10);
Application.ProcessMessages;
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var
i: Real;
begin
TURTLE_INIT;
GO(Screen.Height div 2);
Turn(-90);
Go(Screen.Width div 2);
Turn(90);
PEN_DOWN;
for i in turns do
begin
Turn(i);
GO(50);
end;
PEN_UP;
end;
procedure TForm1.TURTLE_INIT;
begin
x := 0; { Начальное положение - левый }
y := Screen.Height; { нижний угол }
angle := PI / 2; { Начальное направление - "вверх" }
Screen.Canvas.Pen.Color := clGreen;
Screen.Canvas.MoveTo(x, y);
end;
procedure TForm1.GO(distance: Integer);
var newx, newy: Integer;
begin
newx := x + Round(distance * Cos(angle));
newy := y - Round(distance * Sin(angle));
if pen = true then
Screen.Canvas.LineTo(newx, newy)
else
Screen.Canvas.MoveTo(newx, newy);
x := newx;
y := newy;
end;
procedure TForm1.TURN(a: Real);
begin
{ Используем формулу радианы = градусы * PI / 180 }
angle := angle + a * PI / 180;
end;
procedure TForm1.PEN_UP;
begin
pen := false;
end;
procedure TForm1.PEN_DOWN;
begin
pen := true;
end;
end.

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="State automat"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<Units>
<Unit>
<Filename Value="Project1.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="Project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units>
<Unit>
<Filename Value="Project1.pas"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<TopLine Value="81"/>
<CursorPos X="27" Y="105"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit>
</Units>
<JumpHistory HistoryIndex="16">
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="63" Column="31" TopLine="25"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="51" Column="31" TopLine="27"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="76" Column="47" TopLine="45"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="22" Column="37"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="14" Column="5"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="77" Column="16" TopLine="39"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="107" Column="27" TopLine="75"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="86" Column="14" TopLine="75"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="53" Column="5" TopLine="14"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="97" Column="9" TopLine="57"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="103" Column="57" TopLine="67"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="112" Column="59" TopLine="78"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="118" Column="58" TopLine="87"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="122" Column="9" TopLine="98"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="116" Column="62" TopLine="97"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="4" Column="16"/>
</Position>
<Position>
<Filename Value="Project1.pas"/>
<Caret Line="12" Column="12" TopLine="12"/>
</Position>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,228 @@
program Project1;
{$mode objfpc}{$H+}
{$codepage utf8}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
Classes, SysUtils, CustApp
{ you can add units after this };
type StateType = (pay, coffee, cup, back);
type CommandType = (
pay5, pay10, pay20, pay50, pay100, pay200,
chooseblack, choosesugar, coosecappu, choosecacao,
choosecup, choosenocup, payback
);
type
{ TStateMachine }
TStateMachine = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function GetNextCommand: CommandType;
end;
{ TStateMachine }
procedure TStateMachine.DoRun;
var
ErrorMsg: String;
State: StateType = pay;
Command: CommandType;
moneyPayed: Integer = 0;
begin
// quick check parameters
ErrorMsg := CheckOptions('h', 'help');
if ErrorMsg <> '' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
while true do
begin
Command := GetNextCommand;
case State of
pay:
begin
case Command of
pay5:
begin
moneyPayed := moneyPayed + 5;
end;
pay10:
begin
moneyPayed := moneyPayed + 10;
end;
pay20:
begin
moneyPayed := moneyPayed + 20;
end;
pay50:
begin
moneyPayed := moneyPayed + 50;
end;
pay100:
begin
moneyPayed := moneyPayed + 100;
end;
pay200:
begin
moneyPayed := moneyPayed + 200;
end;
chooseblack, choosesugar, coosecappu, choosecacao:
begin
if moneyPayed >= 70 then
begin
State := coffee;
end
else
begin
WriteLn('Вы бросили недостаточно денег.');
end;
end
else
WriteLn('Неверная команда!');
end;
end;
coffee:
begin
case Command of
choosecup, choosenocup:
begin
State := cup;
end;
else
WriteLn('Неверная команда!');
end;
end;
cup:
begin
case Command of
payback:
begin
State := back;
WriteLn('Ваша сдача: ' + IntToStr(moneyPayed - 70));
Break;
end;
else
WriteLn('Неверная команда!');
end;
end;
back:
begin
end;
end;
end;
// stop program loop
Terminate;
end;
constructor TStateMachine.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TStateMachine.Destroy;
begin
inherited Destroy;
end;
function TStateMachine.GetNextCommand: CommandType;
var
Input: String;
begin
Writeln('Введите команду:');
while true do
begin
Readln(Input);
case Input of
'pay5':
begin
Result := pay5;
Exit;
end;
'pay10':
begin
Result := pay10;
Exit;
end;
'pay20':
begin
Result := pay20;
Exit;
end;
'pay50':
begin
Result := pay50;
Exit;
end;
'pay100':
begin
Result := pay100;
Exit;
end;
'pay200':
begin
Result := pay200;
Exit;
end;
'chooseblack':
begin
Result := chooseblack;
Exit;
end;
'choosesugar':
begin
Result := choosesugar;
Exit;
end;
'choosecappu':
begin
Result := coosecappu;
Exit;
end;
'choosecacao':
begin
Result := choosecacao;
Exit;
end;
'choosecup':
begin
Result := choosecup;
Exit;
end;
'choosenocup':
begin
Result := choosenocup;
Exit;
end;
'payback':
begin
Result := payback;
Exit;
end
else Writeln('Команда не существует. Попробуйте еще раз:');
end;
end;
end;
var
Application: TStateMachine;
begin
Application:=TStateMachine.Create(nil);
Application.Title:='State automat';
Application.Run;
Application.Free;
end.

View File

@@ -0,0 +1,109 @@
#include <stdlib.h>
#include <math.h>
#include <gtk/gtk.h>
#include <cairo.h>
struct molecule {
guint x, y, Vx, Vy;
} rand_molecule;
static const gushort R = 10;
static const gushort V = 5;
static guint w_width = 850;
static guint w_height = 550;
static gboolean on_draw_event (GtkWidget *widget, cairo_t *cr, gpointer user_data) {
cr = gdk_cairo_create (gtk_widget_get_window (widget));
// Paint a circle
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
cairo_arc (cr, rand_molecule.x, rand_molecule.y, R, 0, 2 * G_PI);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
// Free memory
cairo_destroy (cr);
return FALSE;
}
static gboolean source_func (gpointer user_data) {
cairo_t *cr;
cr = gdk_cairo_create (gtk_widget_get_window (user_data));
// Move the molecule
rand_molecule.x += rand_molecule.Vx;
rand_molecule.y += rand_molecule.Vy;
if (rand_molecule.x > (w_width - R)) {
rand_molecule.x = w_width - R;
rand_molecule.Vx = -rand_molecule.Vx;
}
if (rand_molecule.x < R) {
rand_molecule.x = R;
rand_molecule.Vx = -rand_molecule.Vx;
}
if (rand_molecule.y > (w_height - R)) {
rand_molecule.y = w_height - R;
rand_molecule.Vy = -rand_molecule.Vy;
}
if (rand_molecule.y < R) {
rand_molecule.y = R;
rand_molecule.Vy = -rand_molecule.Vy;
}
// Paint a circle
cairo_set_source_rgb (cr, 1, 1, 1);
cairo_paint (cr);
cairo_arc (cr, rand_molecule.x, rand_molecule.y, R, 0, 2 * G_PI);
cairo_set_source_rgb (cr, 0, 0, 0);
cairo_set_line_width (cr, 1);
cairo_stroke (cr);
// Free memory
cairo_destroy (cr);
return TRUE;
}
int main (int argc, char **argv) {
double angle;
GRand *rand;
GtkWindow *window;
GtkDrawingArea *darea;
// Init
gtk_init (&argc, &argv);
rand = g_rand_new ();
// Get random coordinates for the first molecule
rand_molecule.x = g_rand_int_range (rand, R, w_width - R);
rand_molecule.y = g_rand_int_range (rand, R, w_height - R);
angle = g_rand_double_range (rand, 0, 360) * G_PI / 180;
// Get the velocity components
rand_molecule.Vx = round (V * sin (angle));
rand_molecule.Vy = round (V * cos (angle));
// Create and configure the window and the needed areas
window = (GtkWindow *)gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_position (window, GTK_WIN_POS_CENTER);
gtk_window_set_default_size (window, w_width, w_height);
gtk_window_set_title (window, "Молекула газа в закрытом сосуде");
darea = (GtkDrawingArea *)gtk_drawing_area_new ();
gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (darea));
gtk_widget_show_all (GTK_WIDGET (window));
g_signal_connect (G_OBJECT (darea), "draw", G_CALLBACK (on_draw_event), NULL);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
g_timeout_add (15, source_func, window);
gtk_main ();
g_rand_free (rand);
return EXIT_SUCCESS;
}

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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="Brownian motion"/>
<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"/>
<HasResources Value="True"/>
<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:='Brownian motion';
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,133 @@
<?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="46"/>
</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="132"/>
<CursorPos X="22" Y="99"/>
<UsageCount Value="46"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="24" HistoryIndex="23">
<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>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="132" TopLine="80"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="36" Column="22" TopLine="9"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="136" Column="37" TopLine="103"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="138" Column="37" TopLine="105"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="194" Column="30" TopLine="145"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="198" Column="43" TopLine="148"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="136" Column="17" TopLine="113"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="43" Column="53" TopLine="13"/>
</Position11>
<Position12>
<Filename Value="unit1.pas"/>
<Caret Line="63" Column="56" TopLine="54"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="202" Column="34" TopLine="153"/>
</Position13>
<Position14>
<Filename Value="unit1.pas"/>
<Caret Line="203" Column="21" TopLine="153"/>
</Position14>
<Position15>
<Filename Value="unit1.pas"/>
<Caret Line="206" Column="9" TopLine="154"/>
</Position15>
<Position16>
<Filename Value="unit1.pas"/>
<Caret Line="200" Column="39" TopLine="153"/>
</Position16>
<Position17>
<Filename Value="unit1.pas"/>
<Caret Line="187" Column="14" TopLine="142"/>
</Position17>
<Position18>
<Filename Value="unit1.pas"/>
<Caret Line="145" Column="39" TopLine="95"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="143" Column="29" TopLine="116"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="106" Column="51" TopLine="85"/>
</Position20>
<Position21>
<Filename Value="unit1.pas"/>
<Caret Line="144" Column="20" TopLine="100"/>
</Position21>
<Position22>
<Filename Value="unit1.pas"/>
<Caret Line="142" Column="14" TopLine="111"/>
</Position22>
<Position23>
<Filename Value="unit1.pas"/>
<Caret Line="141" Column="67" TopLine="114"/>
</Position23>
<Position24>
<Filename Value="unit1.pas"/>
<Caret Line="142" Column="19" TopLine="114"/>
</Position24>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,34 @@
object Form1: TForm1
Left = 268
Height = 493
Top = 247
Width = 1279
Caption = 'Form1'
ClientHeight = 493
ClientWidth = 1279
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object Screen: TPaintBox
Left = 11
Height = 432
Top = 11
Width = 629
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 592
Height = 20
Top = 464
Width = 99
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
object Path: TPaintBox
Left = 640
Height = 432
Top = 11
Width = 629
OnPaint = PathPaint
end
end

View File

@@ -0,0 +1,214 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
Math;
type
Coordinate = record
X, Y: Integer;
end;
Molecule = record
X, Y: Integer;
Vx, Vy: Integer;
{ Указывает на столкновение с броуновской
частицей во время предыдущей итерации }
WasCollision: Boolean;
end;
{ TForm1 }
TForm1 = class(TForm)
Path: TPaintBox;
StartStopBtn: TButton;
Screen: TPaintBox;
procedure PathPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
procedure ScreenPaint(Sender: TObject);
private
const R: Integer = 10; { Радиус молекулы }
V: Integer = 7; { Максимальная скорость молекулы }
N = 30; { Количество молекул }
Rb: Integer = 60; { Радиус броуновской частицы }
K: Real = 0.01; { "Коэффициент передачи" }
var Mol: array[1..N] of Molecule; { Массив молекул }
Xb, Yb: Real; { Координаты броуновской частицы }
Vxb, Vyb: Real; { Составляющие скорости броуновской частицы }
Points: array of Coordinate;
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);
if Sqrt((Mol[i].X - Xb) * (Mol[i].X - Xb) + { Если произошло столкновение }
(Mol[i].Y - Yb) * (Mol[i].Y - Yb)) < Rb + R then
begin
if Mol[i].WasCollision = false then { Если на предыдущей итерации }
begin { эта молекула не сталкивалась с }
Vxb := Vxb + K * Mol[i].Vx; { частицей, обрабатываем }
Vyb := Vyb + K * Mol[i].Vy; { столкновение }
end;
{ На данной итерации i-я молекула столкнулась с броуновской частицей }
Mol[i].WasCollision := true;
end
else
Mol[i].WasCollision := false;
end;
Screen.Canvas.Pen.Color := clBtnFace; { Стереть частицу с экрана }
Screen.Canvas.Ellipse(Round(Xb - Rb), Round(Yb - Rb),
Round(Xb + Rb), Round(Yb + Rb));
Xb := Xb + Vxb; { Сдвинуть на новую позицию }
Yb := Yb + Vyb;
if Xb > Screen.Width - Rb then { Обработать отражения от стенок аквариума }
begin
Xb := Screen.Width - Rb;
Vxb := -Vxb;
end;
if Xb < Rb then
begin
Xb := Rb;
Vxb := -Vxb;
end;
if Yb > Screen.Height - Rb then
begin
Yb := Screen.Height - Rb;
Vyb := -Vyb;
end;
if Yb < Rb then
begin
Yb := Rb;
Vyb := -Vyb;
end;
if (Length(points) < (Screen.Width - Rb) * (Screen.Height - Rb)) and
(Round(Xb) mod 2 = 0) and (Round(Yb) mod 2 = 0) then
begin
SetLength(points, Length(points) + 1);
points[Length(points) - 1].X := Round(Xb);
points[Length(points) - 1].Y := Round(Yb);
end;
Screen.Canvas.Pen.Color := clRed; { Нарисовать частицу на новом месте }
Screen.Canvas.Ellipse(Round(Xb - Rb), Round(Yb - Rb),
Round(Xb + Rb), Round(Yb + Rb));
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;
Xb := Screen.Width div 2;
Yb := Screen.Height div 2;
Vxb := 0;
Vyb := 0;
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)); { скорости молекулы }
Mol[i].WasCollision := false;
end;
while IsRunning do { Основной цикл }
begin
Screen.Invalidate;
Path.Repaint;
Sleep(10); { Пауза на 10 миллисекунд }
Application.ProcessMessages;
if Application.Terminated then Break;
end;
end;
procedure TForm1.PathPaint(Sender: TObject);
var i: Integer;
begin
if Length(points) = 0 then Exit;
Screen.Canvas.Pen.Color := clBlue;
for i := 0 to Length(points) do
begin
Path.Canvas.Rectangle(points[i].X - 1, points[i].Y - 1,
points[i].X + 1, points[i].Y + 1);
end;
end;
end.

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="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="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>

View File

@@ -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.

View File

@@ -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>

View File

@@ -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

View File

@@ -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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="falling_ball"/>
<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="falling_ball.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="falling_ball"/>
</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 falling_ball;
{$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,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="2">
<Unit0>
<Filename Value="falling_ball.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="26"/>
</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="81"/>
<CursorPos X="3" Y="107"/>
<UsageCount Value="26"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="11" HistoryIndex="10">
<Position1>
<Filename Value="unit1.pas"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="46" Column="10"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="64" Column="19" TopLine="13"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="91" Column="13" TopLine="37"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="89" Column="23" TopLine="46"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="9"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="104" Column="28" TopLine="53"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="105" Column="38" TopLine="52"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="104" Column="38" TopLine="53"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="102" Column="39" TopLine="72"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="123" Column="70" TopLine="79"/>
</Position11>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,27 @@
object Form1: TForm1
Left = 227
Height = 575
Top = 577
Width = 986
Caption = 'Form1'
ClientHeight = 575
ClientWidth = 986
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object Screen: TPaintBox
Left = 8
Height = 474
Top = 9
Width = 968
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 440
Height = 31
Top = 509
Width = 112
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
end

View File

@@ -0,0 +1,141 @@
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 R: Integer = 10; { Радиус шара }
Vx0: Integer = 3; { Горизонтальная скорость шара }
a: Real = 1; { Ускорение }
K: Real = 0.8; { Коэффицент потери }
var X, Y: Integer; { Координаты шара }
public
end;
var
Form1: TForm1;
IsRunning: Boolean = false;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
var Vx, Vy: Real; { Состовляющие скорости }
begin
if IsRunning then
begin
IsRunning := false;
StartStopBtn.Caption := 'Пуск';
Exit;
end;
StartStopBtn.Caption := 'Стоп';
IsRunning := true;
Vy := 0; { Вертикальная состовляющая скорости изначально равна нулю }
Vx := Vx0;
X := R + 5; { Начальное }
Y := Screen.Height div 2; { положение шара }
Screen.Invalidate;
Application.ProcessMessages;
Sleep(500); { Пауза, чтобы увидеть начальное положение на экране }
while IsRunning do { Основной цикл }
begin
{ Screen.Canvas.Pen.Color := ClBtnFace;
Screen.Canvas.Ellipse(X - R, Y - R, X + R, Y + R); }
X := X + Round(Vx); { Сдвигаем на новую позицию }
Y := Y + Round(Vy);
if X > Screen.Width - R then { Если шар вышел за экран, "нажимаем" }
Form1.StartStopBtnClick(nil); { кнопку StartStopBtn (1) }
if Y > Screen.Height - R then { Если шар стокнулся с землей }
begin
{ "Отражаем" - как в предыдущих моделях но скорость уменьшается
в K раз если скорость стала по модулю (2) меньше единицы ,
"нажимаем" StartStopBtn }
Y := Screen.Height - R;
Vy := -Vy * K;
if abs(Vy) < 1 then Form1.StartStopBtnClick(nil);
end;
Vy := Vy + a; { Изменяем скорость в соответствии с ускорением }
Screen.Invalidate;
Sleep(3);
Application.ProcessMessages;
end;
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var T, U: Integer;
Vt, Vu: Real;
begin
if not IsRunning then Exit;
Vu := 0; { Вертикальная состовляющая скорости изначально равна нулю }
Vt := Vx0;
T := R + 5; { Начальное }
U := Screen.Height div 2; { положение шара }
Screen.Canvas.Pen.Color := clBlack; { Рисуем "подставку" }
Screen.Canvas.MoveTo(R + 5, Screen.Height div 2 + R); { на которой }
Screen.Canvas.LineTo(R + 5, Screen.Height); { лежит шар }
Screen.Canvas.Brush.Color := clBlue;
Screen.Canvas.Brush.Style := bsSolid;
Screen.Canvas.Pen.Color := clBlue;
Screen.Canvas.Ellipse(T - R, U - R, T + R, U + R); { рисуем шар }
while (T < X) or (U < Y) do
begin
T := T + Round(Vt); { Сдвигаем на новую позицию }
U := U + Round(Vu);
if T > Screen.Width - R then { Если шар вышел за экран, "нажимаем" }
Form1.StartStopBtnClick(nil); { кнопку StartStopBtn (1) }
if U > Screen.Height - R then { Если шар стокнулся с землей }
begin
{ "Отражаем" - как в предыдущих моделях но скорость уменьшается
в K раз если скорость стала по модулю (2) меньше единицы ,
"нажимаем" StartStopBtn }
U := Screen.Height - R;
Vu := -Vu * K;
if abs(Vu) < 1 then Form1.StartStopBtnClick(nil);
end;
Vu := Vu + a; { Изменяем скорость в соответствии с ускорением }
Screen.Canvas.Brush.Color := clBlue;
Screen.Canvas.Brush.Style := bsSolid;
Screen.Canvas.Pen.Color := clBlue; { рисуем шар на }
Screen.Canvas.Pen.Style := psSolid;;
Screen.Canvas.Ellipse(T - R, U - R, T + R, U + R); { новой позиции }
end;
end;
end.

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="project1"/>
<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,22 @@
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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,61 @@
<?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"/>
<TopLine Value="22"/>
<CursorPos X="9" Y="52"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="6" HistoryIndex="5">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="26"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="22" Column="27"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="26" Column="27"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="28" Column="27"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="82" Column="5" TopLine="27"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="103" TopLine="51"/>
</Position6>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,27 @@
object Form1: TForm1
Left = 597
Height = 560
Top = 476
Width = 845
Caption = 'Form1'
ClientHeight = 560
ClientWidth = 845
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object Screen: TPaintBox
Left = 11
Height = 466
Top = 6
Width = 820
OnPaint = ScreenPaint
end
object StartStopBtn: TButton
Left = 387
Height = 27
Top = 490
Width = 72
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
end

View File

@@ -0,0 +1,107 @@
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
var EarthX, EarthY: Integer; { Координаты земли }
EarthA: Real; { Текущий угол отклонения Земли }
MoonX, MoonY: Integer; { Координаты Луны }
MoonA: Real; { Текущий угол отклонения Луны }
IsRunning: Boolean;
const SunR: Integer = 60; { Радиус Солнца }
EarthR: Integer = 20; { Радиус Земли }
MoonR: Integer = 4; { Радиус Луны }
EarthD: Integer = 140; { Расстояние от Солнца до Земли }
MoonD: Integer = 40; { Радиус от Земли до Луны }
EarthV: Real = 0.02; { Угловая скорость Земли }
MoonV: Real = 0.1; { Угловая скорость Луны }
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
begin
if IsRunning then
begin
IsRunning := false;
StartStopBtn.Caption := 'Пуск';
Exit;
end;
StartStopBtn.Caption := 'Стоп';
IsRunning := true;
{ Инициализация переменных }
EarthA := 0;
MoonA := 0;
EarthX := 0;
EarthY := 0;
MoonX := 0;
MoonY := 0;
while IsRunning do { Основной цикл }
begin
{ Пересчитаем координаты Земли и Луны }
EarthX := Round(Screen.Width div 2 + EarthD * Cos(EarthA));
EarthY := Round(Screen.Height div 2 + EarthD * Sin(EarthA));
MoonX := Round(EarthX + MoonD * Cos(MoonA));
MoonY := Round(EarthY + MoonD * Sin(MoonA));
EarthA := EarthA + EarthV; { Изменяем текущие углы отклонения }
MoonA := MoonA + MoonV; { Земли и Луны }
if EarthA > 2 * PI then EarthA := EarthA - 2 * PI; { Корректируем углы }
if MoonA > 2 * PI then MoonA := MoonA - 2 * PI; { если требуется }
Screen.Invalidate;
Sleep(30); { Пауза }
Application.ProcessMessages;
if Application.Terminated then break;
end;
end;
procedure TForm1.ScreenPaint(Sender: TObject);
begin
if not IsRunning then Exit;
Screen.Canvas.Pen.Width := 5; { Толщина линий - 5 пикселей }
Screen.Canvas.Pen.Color := clRed; { Рисуем Солнце в центре экрана }
Screen.Canvas.Ellipse(Screen.Width div 2 - SunR,
Screen.Height div 2 - SunR,
Screen.Width div 2 + SunR,
Screen.Height div 2 + SunR);
Screen.Canvas.Pen.Color := clGreen; { Рисуем Землю }
Screen.Canvas.Ellipse(EarthX - EarthR, EarthY - EarthR,
EarthX + EarthR, EarthY + EarthR); { и Луну }
Screen.Canvas.Pen.Color := clBlue;
Screen.Canvas.Ellipse(MoonX - MoonR, MoonY - MoonR,
MoonX + MoonR, MoonY + MoonR);
end;
end.

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</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>
<Units Count="1">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</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,39 @@
program project1;
uses Crt, Math, SysUtils;
var N, NO: Integer;
x, y: Integer;
Sum: Real;
IsRunning: Boolean;
const R: Integer = 20000; { Радиус круга }
begin
IsRunning := true;
N := 0;
NO := 0;
Sum := 0;
Randomize;
ClrScr;
while IsRunning do
begin
Inc(N); { Количество экспериментов }
x := RandomRange(-R, R); { Определяем случайную точку }
y := RandomRange(-R, R);
if Sqrt(x * x + y * y) <= R then NO := NO + 1; { Если она лежит в круге }
Sum := Sum + 4 * NO / N;
GotoXY(1, 1);
WriteLn('Количество точек: ', IntToStr(N));
WriteLn('Текущее значение PI: ', FloatToStr(4 * NO / N));
WriteLn('Среднее значение PI: ', FloatToStr(Sum / N));
if KeyPressed and (ReadKey = ^C) then IsRunning := false;
end;
end.

View File

@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="11"/>
<BuildModes Active="Default"/>
<Units Count="1">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<IsVisibleTab Value="True"/>
<CursorPos X="13" Y="27"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit0>
</Units>
<JumpHistory Count="14" HistoryIndex="13">
<Position1>
<Filename Value="project1.lpr"/>
<Caret Line="7" Column="5"/>
</Position1>
<Position2>
<Filename Value="project1.lpr"/>
<Caret Line="16" Column="3"/>
</Position2>
<Position3>
<Filename Value="project1.lpr"/>
<Caret Line="3" Column="13"/>
</Position3>
<Position4>
<Filename Value="project1.lpr"/>
<Caret Line="2"/>
</Position4>
<Position5>
<Filename Value="project1.lpr"/>
<Caret Line="3" Column="11"/>
</Position5>
<Position6>
<Filename Value="project1.lpr"/>
<Caret Line="15" Column="3"/>
</Position6>
<Position7>
<Filename Value="project1.lpr"/>
<Caret Line="3" Column="10"/>
</Position7>
<Position8>
<Filename Value="project1.lpr"/>
<Caret Line="15" Column="3"/>
</Position8>
<Position9>
<Filename Value="project1.lpr"/>
<Caret Line="23" Column="29"/>
</Position9>
<Position10>
<Filename Value="project1.lpr"/>
<Caret Line="31" Column="33"/>
</Position10>
<Position11>
<Filename Value="project1.lpr"/>
<Caret Line="3" Column="23"/>
</Position11>
<Position12>
<Filename Value="project1.lpr"/>
<Caret Line="29" Column="12"/>
</Position12>
<Position13>
<Filename Value="project1.lpr"/>
<Caret Line="27" Column="50"/>
</Position13>
<Position14>
<Filename Value="project1.lpr"/>
<Caret Line="3" Column="25"/>
</Position14>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="1" ActiveMode="default">
<Mode0 Name="default">
<local>
<LaunchingApplication Use="True" PathPlusParams="/usr/bin/kitty --title 'Lazarus Run Output' $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</Mode0>
</Modes>
</RunParams>
</ProjectSession>
</CONFIG>

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<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"/>
<HasResources Value="True"/>
<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,22 @@
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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,158 @@
<?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="41"/>
</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="44"/>
<CursorPos X="30" Y="79"/>
<UsageCount Value="41"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="3"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="12" TopLine="11"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="12"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="21"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="20"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="13"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="9"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="13" Column="17"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="31" Column="3"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="37" Column="47" TopLine="6"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="97" Column="16" TopLine="38"/>
</Position11>
<Position12>
<Filename Value="unit1.pas"/>
<Caret Line="9" Column="7"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="76" Column="21" TopLine="24"/>
</Position13>
<Position14>
<Filename Value="unit1.pas"/>
<Caret Line="25" Column="6"/>
</Position14>
<Position15>
<Filename Value="unit1.pas"/>
<Caret Line="96" Column="6" TopLine="41"/>
</Position15>
<Position16>
<Filename Value="unit1.pas"/>
<Caret Line="26" Column="21"/>
</Position16>
<Position17>
<Filename Value="unit1.pas"/>
<Caret Line="25" Column="16"/>
</Position17>
<Position18>
<Filename Value="unit1.pas"/>
<Caret Line="41" Column="6" TopLine="21"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="46" Column="13" TopLine="23"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="40" Column="60" TopLine="6"/>
</Position20>
<Position21>
<Filename Value="unit1.pas"/>
<Caret Line="41" Column="21" TopLine="9"/>
</Position21>
<Position22>
<Filename Value="unit1.pas"/>
<Caret Line="40" Column="50" TopLine="12"/>
</Position22>
<Position23>
<Filename Value="unit1.pas"/>
<Caret Line="42" Column="63" TopLine="14"/>
</Position23>
<Position24>
<Filename Value="unit1.pas"/>
<Caret Line="87" Column="43" TopLine="34"/>
</Position24>
<Position25>
<Filename Value="unit1.pas"/>
<Caret Line="13" Column="4"/>
</Position25>
<Position26>
<Filename Value="unit1.pas"/>
<Caret Line="12" Column="3"/>
</Position26>
<Position27>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="3"/>
</Position27>
<Position28>
<Filename Value="unit1.pas"/>
<Caret Line="35" Column="23"/>
</Position28>
<Position29>
<Filename Value="unit1.pas"/>
<Caret Line="89" Column="15" TopLine="53"/>
</Position29>
<Position30>
<Filename Value="unit1.pas"/>
<Caret Line="93" Column="60" TopLine="58"/>
</Position30>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,27 @@
object Form1: TForm1
Left = -340
Height = 636
Top = 427
Width = 904
Caption = 'Form1'
ClientHeight = 636
ClientWidth = 904
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object StartStopBtn: TButton
Left = 416
Height = 25
Top = 600
Width = 76
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
object Screen: TPaintBox
Left = 10
Height = 571
Top = 11
Width = 882
OnPaint = ScreenPaint
end
end

View File

@@ -0,0 +1,158 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Math;
const FieldWidth = 30; { Ширина и }
FieldHeight = 25; { высота поля }
type
TField = array [0..FieldWidth + 1, 0..FieldHeight + 1] of Boolean;
TPoint = record
x: Integer;
y: Integer;
end;
{ TForm1 }
TForm1 = class(TForm)
Screen: TPaintBox;
StartStopBtn: TButton;
procedure ScreenPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
private
procedure UpdateSurface(field: TField; point: TPoint; neighbours: Integer);
var Rx, Ry: Integer; { Ширина, высота клекти }
BlueField, GreenField: TField;
s, v: Integer;
bluePoint, greenPoint: TPoint;
public
end;
var
Form1: TForm1;
IsRunning: Boolean;
implementation
{$R *.lfm}
function CountNeighbours(Field: TField; x: Integer; y: Integer): Integer;
var i, j: Integer;
begin
Result := 0;
for i := -1 to 1 do
for j := -1 to 1 do
Result := Result + Ord(Field[x + i][y + j]);
Result := Result - Ord(Field[x][y]);
end;
{ Выбираем случайную клекту }
function ChoosePoint(): TPoint;
begin
Result.x := RandomRange(1, FieldWidth);
Result.y := RandomRange(1, FieldHeight);
end;
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
var i, j: 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;
Randomize;
for i := 0 to FieldWidth + 1 do { Очистка поля }
for j := 0 to FieldHeight + 1 do
begin
BlueField[i, j] := false;
GreenField[i, j] := false;
end;
while IsRunning do { Основной цикл }
begin
bluePoint := ChoosePoint();
greenPoint := ChoosePoint();
s := CountNeighbours(BlueField, bluePoint.x, bluePoint.y);
v := CountNeighbours(GreenField, greenPoint.x, greenPoint.y);
Screen.Invalidate;
Sleep(250);
Application.ProcessMessages;
if Application.Terminated then Exit;
end
end;
procedure TForm1.UpdateSurface(field: TField; point: TPoint; neighbours: Integer);
begin
if (field[point.x, point.y] = false) and (neighbours > 2) then { Создаем новую инфузорию }
begin
Screen.Canvas.Pen.Color := clBlue;
Screen.Canvas.Ellipse((2 * point.x - 1) * Rx - Rx, (2 * point.y - 1) * Ry - Ry,
(2 * point.x - 1) * Rx + Rx, (2 * point.y -1) * Ry + Ry);
field[point.x, point.y] := true;
end
else if (field[point.x, point.y] = true) and ((neighbours < 3) or (neighbours > 4)) then { Удаляем }
begin
Screen.Canvas.Pen.Color := clBtnFace;
Screen.Canvas.Ellipse((2 * point.x - 1) * Rx - Rx, (2 * bluePoint.y - 1) * Ry - Ry,
(2 * point.x - 1) * Rx + Rx, (2 * point.y -1) * Ry + Ry);
field[point.x, point.y] := false;
end;
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var i, j: Integer;
begin
Screen.Canvas.Pen.Color := clBlue;
for i := 1 to FieldWidth do { Создаем начальную конфигурацию }
for j := 1 to FieldHeight do
if Random(4) = 0 then { В среднем будет одна инфузория }
begin { на четыре клетки }
BlueField[i, j] := true;
Screen.Canvas.Ellipse((2 * i - 1) * Rx - Rx, (2 * j - 1) * Ry - Ry,
(2 * i - 1) * Rx + Rx, (2 * j - 1) * Ry + Ry);
end;
UpdateSurface(blueField, bluePoint, s);
Screen.Canvas.Pen.Color := clGreen;
for i := 1 to FieldWidth do { Создаем начальную конфигурацию }
for j := 1 to FieldHeight do
if Random(4) = 0 then { В среднем будет одна инфузория }
begin { на четыре клетки }
GreenField[i, j] := true;
Screen.Canvas.Ellipse((2 * i - 1) * Rx - Rx, (2 * j - 1) * Ry - Ry,
(2 * i - 1) * Rx + Rx, (2 * j - 1) * Ry + Ry);
end;
UpdateSurface(greenField, greenPoint, v);
end;
end.

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="project1"/>
<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="project1.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="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,22 @@
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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectSession>
<Version Value="12"/>
<BuildModes Active="Default"/>
<Units Count="3">
<Unit0>
<Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/>
<EditorIndex Value="-1"/>
<WindowIndex Value="-1"/>
<TopLine Value="-1"/>
<CursorPos X="-1" Y="-1"/>
<UsageCount Value="25"/>
</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="131"/>
<CursorPos X="31" Y="118"/>
<UsageCount Value="25"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
<Unit2>
<Filename Value="../9_conway/unit1.pas"/>
<UnitName Value="Unit1"/>
<EditorIndex Value="-1"/>
<TopLine Value="13"/>
<UsageCount Value="10"/>
</Unit2>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="103" Column="52" TopLine="35"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="105" Column="52" TopLine="39"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="5" TopLine="4"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="3"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="12" TopLine="11"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="12"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="21"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="20"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="13"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="9"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="13" Column="17"/>
</Position11>
<Position12>
<Filename Value="unit1.pas"/>
<Caret Line="31" Column="3"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="37" Column="47" TopLine="6"/>
</Position13>
<Position14>
<Filename Value="unit1.pas"/>
<Caret Line="97" Column="16" TopLine="38"/>
</Position14>
<Position15>
<Filename Value="unit1.pas"/>
<Caret Line="9" Column="7"/>
</Position15>
<Position16>
<Filename Value="unit1.pas"/>
<Caret Line="76" Column="21" TopLine="24"/>
</Position16>
<Position17>
<Filename Value="unit1.pas"/>
<Caret Line="25" Column="6"/>
</Position17>
<Position18>
<Filename Value="unit1.pas"/>
<Caret Line="96" Column="6" TopLine="41"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="26" Column="21"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="68"/>
</Position20>
<Position21>
<Filename Value="unit1.pas"/>
<Caret Line="89" Column="23" TopLine="30"/>
</Position21>
<Position22>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="68" TopLine="14"/>
</Position22>
<Position23>
<Filename Value="unit1.pas"/>
<Caret Line="88" Column="23" TopLine="27"/>
</Position23>
<Position24>
<Filename Value="unit1.pas"/>
<Caret Line="120" Column="43" TopLine="55"/>
</Position24>
<Position25>
<Filename Value="unit1.pas"/>
<Caret Line="88" Column="45" TopLine="33"/>
</Position25>
<Position26>
<Filename Value="unit1.pas"/>
<Caret Line="106" Column="15" TopLine="46"/>
</Position26>
<Position27>
<Filename Value="unit1.pas"/>
<Caret Line="78" Column="14" TopLine="42"/>
</Position27>
<Position28>
<Filename Value="unit1.pas"/>
<Caret Line="108" Column="28" TopLine="54"/>
</Position28>
<Position29>
<Filename Value="unit1.pas"/>
<Caret Line="103" Column="52" TopLine="69"/>
</Position29>
<Position30>
<Filename Value="unit1.pas"/>
<Caret Line="157" Column="44" TopLine="97"/>
</Position30>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,26 @@
object Form1: TForm1
Left = 1048
Height = 675
Top = 310
Width = 933
Caption = 'Form1'
ClientHeight = 675
ClientWidth = 933
LCLVersion = '2.2.2.0'
object StartStopBtn: TButton
Left = 429
Height = 26
Top = 619
Width = 78
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
object Screen: TPaintBox
Left = 10
Height = 589
Top = 11
Width = 910
OnPaint = ScreenPaint
end
end

View File

@@ -0,0 +1,214 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Math;
const FieldWidth = 30; { Ширина и }
FieldHeight = 25; { высота поля }
type
TField = array [0..FieldWidth + 1, 0..FieldHeight + 1] of Integer;
{ TForm1 }
TForm1 = class(TForm)
Screen: TPaintBox;
StartStopBtn: TButton;
procedure ScreenPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
private
var Rx, Ry: Integer; { Ширина, высота клекти }
Field: TField;
x, y: Integer;
public
end;
var
Form1: TForm1;
IsRunning: Boolean;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
var i, j: Integer;
protoplasmCount, infusoria: Integer;
direction, positionX, positionY, energy: 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;
Randomize;
for i := 0 to FieldWidth + 1 do { Очистка поля }
for j := 0 to FieldHeight + 1 do
Field[i, j] := 0;
while IsRunning do { Основной цикл }
begin
x := RandomRange(1, FieldWidth); { Выбираем случайную клекту }
y := RandomRange(1, FieldHeight);
{ Подсчитываем соседей }
infusoria := 0;
protoplasmCount := 0;
for i := -1 to 1 do
for j := -1 to 1 do
begin
if Field[x + i][y + j] = -2 then
begin
Inc(protoplasmCount);
end
else if Field[x + i][y + j] = -1 then
begin
Inc(infusoria);
end;
end;
if Field[x][y] = -1 then
Dec(infusoria);
if (Field[x, y] = 0) and (infusoria > 2) then { Создаем новую инфузорию }
begin
Field[x, y] := -1;
end
{ Удаляем инфузорию }
else if (Field[x, y] = -1) and ((infusoria < 3) or (infusoria > 4)) then
begin
Field[x, y] := 0;
end
{ Создаем инфузория, если достаточно протоплазмы }
else if ((Field[x, y] = 0) or (Field[x, y] = -2)) and
(protoplasmCount > 6) then
begin
for i := -1 to 1 do
for j := -1 to 1 do
if Field[x + i, y + j] = -2 then
Field[x + i, y + j] := 0;
Field[x, y] := -1;
end
{ Создаем протоплазму, если клетка пустая }
else if Field[x, y] = 0 then
begin
Field[x, y] := -2;
end
{ Животное двигается }
else if Field[x, y] > 0 then
begin
direction := Random(4);
energy := Field[x, y];
case direction of
0:
begin
positionX := x - 1;
positionY := y;
end;
1:
begin
positionX := x + 1;
positionY := y;
end;
2:
begin
positionX := x;
positionY := y - 1;
end;
3:
begin
positionX := x;
positionY := y + 1;
end;
end;
if Field[positionX, positionY] = 0 then
Dec(energy)
else if Field[positionX, positionY] = -1 then
Inc(energy)
else if Field[positionX, positionY] > 0 then
energy := energy + Field[positionX, positionY];
Field[x, y] := 0;
if energy > 0 then
Field[positionX, positionY] := energy
end;
{ Создаем животных }
for i := 1 to FieldWidth do
begin
for j := 1 to FieldHeight do
begin
if (Field[i - 1, j] = -1) and
(Field[i, j] = -1) and (Field[i + 1, j] = -1) then
begin
Field[i - 1, j] := 0;
Field[i, j] := 5;
Field[i + 1, j] := 0;
end
else if (Field[i, j - 1] = -1) and
(Field[i, j] = -1) and (Field[i, j + 1] = -1) then
begin
Field[i, j - 1] := 0;
Field[i, j] := 5;
Field[i, j + 1] := 0;
end;
end;
end;
Screen.Invalidate;
Sleep(5);
Application.ProcessMessages;
if Application.Terminated then Exit;
end
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var i, j: Integer;
begin
Screen.Canvas.Pen.Color := clBlue;
for i := 1 to FieldWidth do
begin
for j := 1 to FieldHeight do
begin
if Field[i][j] = -1 then
begin
Screen.Canvas.Pen.Color := clBlue;
Screen.Canvas.Ellipse((2 * i - 1) * Rx - Rx, (2 * j - 1) * Ry - Ry,
(2 * i - 1) * Rx + Rx, (2 * j -1) * Ry + Ry);
end
else if Field[i][j] = -2 then
begin
Screen.Canvas.Pen.Color := clGreen;
Screen.Canvas.Ellipse((2 * i - 1) * Rx - Rx, (2 * j - 1) * Ry - Ry,
(2 * i - 1) * Rx + Rx, (2 * j -1) * Ry + Ry);
end
else if Field[i][j] > 0 then
begin
Screen.Canvas.Pen.Color := clYellow;
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;
end;
end.

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="project1"/>
<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"/>
<HasResources Value="True"/>
<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,22 @@
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.Scaled:=True;
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

View File

@@ -0,0 +1,117 @@
<?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="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"/>
<CursorPos X="14" Y="26"/>
<UsageCount Value="22"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
</Unit1>
</Units>
<JumpHistory Count="20" HistoryIndex="19">
<Position1>
<Filename Value="unit1.pas"/>
<Caret Line="56" Column="13"/>
</Position1>
<Position2>
<Filename Value="unit1.pas"/>
<Caret Line="103" Column="52" TopLine="35"/>
</Position2>
<Position3>
<Filename Value="unit1.pas"/>
<Caret Line="105" Column="52" TopLine="39"/>
</Position3>
<Position4>
<Filename Value="unit1.pas"/>
<Caret Line="21" Column="5" TopLine="4"/>
</Position4>
<Position5>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="3"/>
</Position5>
<Position6>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="12" TopLine="11"/>
</Position6>
<Position7>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="12"/>
</Position7>
<Position8>
<Filename Value="unit1.pas"/>
<Caret Line="20" Column="21"/>
</Position8>
<Position9>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="20"/>
</Position9>
<Position10>
<Filename Value="unit1.pas"/>
<Caret Line="15" Column="13"/>
</Position10>
<Position11>
<Filename Value="unit1.pas"/>
<Caret Line="8" Column="9"/>
</Position11>
<Position12>
<Filename Value="unit1.pas"/>
<Caret Line="13" Column="17"/>
</Position12>
<Position13>
<Filename Value="unit1.pas"/>
<Caret Line="31" Column="3"/>
</Position13>
<Position14>
<Filename Value="unit1.pas"/>
<Caret Line="37" Column="47" TopLine="6"/>
</Position14>
<Position15>
<Filename Value="unit1.pas"/>
<Caret Line="97" Column="16" TopLine="38"/>
</Position15>
<Position16>
<Filename Value="unit1.pas"/>
<Caret Line="9" Column="7"/>
</Position16>
<Position17>
<Filename Value="unit1.pas"/>
<Caret Line="76" Column="21" TopLine="24"/>
</Position17>
<Position18>
<Filename Value="unit1.pas"/>
<Caret Line="25" Column="6"/>
</Position18>
<Position19>
<Filename Value="unit1.pas"/>
<Caret Line="96" Column="6" TopLine="41"/>
</Position19>
<Position20>
<Filename Value="unit1.pas"/>
<Caret Line="26" Column="21"/>
</Position20>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0" ActiveMode=""/>
</RunParams>
</ProjectSession>
</CONFIG>

View File

@@ -0,0 +1,27 @@
object Form1: TForm1
Left = 0
Height = 654
Top = 738
Width = 904
Caption = 'Form1'
ClientHeight = 654
ClientWidth = 904
DesignTimePPI = 93
LCLVersion = '2.0.12.0'
object StartStopBtn: TButton
Left = 416
Height = 25
Top = 600
Width = 76
Caption = 'Пуск'
OnClick = StartStopBtnClick
TabOrder = 0
end
object Screen: TPaintBox
Left = 10
Height = 571
Top = 11
Width = 882
OnPaint = ScreenPaint
end
end

View File

@@ -0,0 +1,119 @@
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
Math;
const FieldWidth = 30; { Ширина и }
FieldHeight = 25; { высота поля }
type
TField = array [0..FieldWidth + 1, 0..FieldHeight + 1] of Boolean;
{ TForm1 }
TForm1 = class(TForm)
Screen: TPaintBox;
StartStopBtn: TButton;
procedure ScreenPaint(Sender: TObject);
procedure StartStopBtnClick(Sender: TObject);
private
var Rx, Ry: Integer; { Ширина, высота клекти }
Field: TField;
x, y, s: Integer;
public
end;
var
Form1: TForm1;
IsRunning: Boolean;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.StartStopBtnClick(Sender: TObject);
var i, j: 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;
Randomize;
for i := 0 to FieldWidth + 1 do { Очистка поля }
for j := 0 to FieldHeight + 1 do
Field[i, j] := false;
for i := 1 to FieldWidth do { Создаем начальную конфигурацию }
for j := 1 to FieldHeight do
if Random(4) = 0 then { В среднем будет одна инфузория }
begin { на четыре клетки }
Field[i, j] := true;
end;
while IsRunning do { Основной цикл }
begin
x := RandomRange(1, FieldWidth); { Выбираем случайную клекту }
y := RandomRange(1, FieldHeight);
s := 0; { Подсчитываем соседей }
for i := -1 to 1 do
for j := -1 to 1 do
s := s + Ord(Field[x + i][y + j]);
s := s - Ord(Field[x][y]);
if (Field[x, y] = false) and (s > 2) then { Создаем новую инфузорию }
begin
Field[x, y] := true;
end
else if (Field[x, y] = true) and ((s < 3) or (s > 4)) then { Удаляем }
begin
Field[x, y] := false;
end;
Screen.Invalidate;
Sleep(5);
Application.ProcessMessages;
if Application.Terminated then Exit;
end
end;
procedure TForm1.ScreenPaint(Sender: TObject);
var i, j: Integer;
begin
Screen.Canvas.Pen.Color := clBlue;
for i := 1 to FieldWidth do
begin
for j := 1 to FieldHeight do
begin
if Field[i][j] then
begin
Screen.Canvas.Pen.Color := clBlue;
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;
end;
end.

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.