From c1147629f7aae2ee90ccd7c9f1ccbf106361d486 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sat, 13 Dec 2025 16:35:46 +0100 Subject: =?UTF-8?q?Add=20book=20"=D0=97=D0=B0=D0=BD=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1/10_turtle/project1.ico" | Bin 0 -> 137040 bytes .../1/10_turtle/project1.lpi" | 79 +++++++++++ .../1/10_turtle/project1.lpr" | 22 +++ .../1/10_turtle/project1.lps" | 156 +++++++++++++++++++++ .../1/10_turtle/project1.res" | Bin 0 -> 139096 bytes .../1/10_turtle/unit1.lfm" | 35 +++++ .../1/10_turtle/unit1.pas" | 139 ++++++++++++++++++ 7 files changed, 431 insertions(+) create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.ico" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpi" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpr" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lps" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.res" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.lfm" create mode 100644 "\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.pas" (limited to 'Занимательное программирование/1/10_turtle') diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.ico" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.ico" new file mode 100644 index 0000000..0341321 Binary files /dev/null and "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.ico" differ diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpi" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpi" new file mode 100644 index 0000000..6175920 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpi" @@ -0,0 +1,79 @@ + + + + + + + + + + + <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> diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpr" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpr" new file mode 100644 index 0000000..c08a82d --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lpr" @@ -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. + diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lps" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lps" new file mode 100644 index 0000000..78e320b --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.lps" @@ -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> diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.res" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.res" new file mode 100644 index 0000000..bec39b4 Binary files /dev/null and "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/project1.res" differ diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.lfm" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.lfm" new file mode 100644 index 0000000..bbc813d --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.lfm" @@ -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 diff --git "a/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.pas" "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.pas" new file mode 100644 index 0000000..d60afb2 --- /dev/null +++ "b/\320\227\320\260\320\275\320\270\320\274\320\260\321\202\320\265\320\273\321\214\320\275\320\276\320\265 \320\277\321\200\320\276\320\263\321\200\320\260\320\274\320\274\320\270\321\200\320\276\320\262\320\260\320\275\320\270\320\265/1/10_turtle/unit1.pas" @@ -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. + -- cgit v1.2.3