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

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

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