{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f8613e2e",
   "metadata": {},
   "source": [
    "# 06-04 · Мини-проекты: квадрат и шестиугольник\n",
    "\n",
    "Практика к разделу [«Мини-проекты: квадрат и шестиугольник»](../../site/chapters/glava-06/06-04-mini-proekty-figury.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ee85efe",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Нарисовать первые настоящие фигуры: квадрат и шестиугольник."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "722e3b47",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "24097985",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:30.284359Z",
     "iopub.status.busy": "2026-08-14T20:52:30.284183Z",
     "iopub.status.idle": "2026-08-14T20:52:30.454032Z",
     "shell.execute_reply": "2026-08-14T20:52:30.453601Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Окно Turtle готово.\n"
     ]
    }
   ],
   "source": [
    "import turtle\n",
    "\n",
    "screen = turtle.Screen()\n",
    "artist = turtle.Turtle()\n",
    "artist.speed(0)\n",
    "print(\"Окно Turtle готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25f7c429",
   "metadata": {},
   "source": [
    "## Рабочий пример — квадрат"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "47f4599a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:30.455141Z",
     "iopub.status.busy": "2026-08-14T20:52:30.455008Z",
     "iopub.status.idle": "2026-08-14T20:52:31.350709Z",
     "shell.execute_reply": "2026-08-14T20:52:31.350005Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Курс после квадрата: 0.0\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "for _ in range(4):\n",
    "    artist.forward(100)\n",
    "    artist.right(90)\n",
    "print(\"Курс после квадрата:\", artist.heading())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8da7529",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — шестиугольник\n",
    "\n",
    "Угол поворота = 360 / количество сторон."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "217106d5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:31.351952Z",
     "iopub.status.busy": "2026-08-14T20:52:31.351814Z",
     "iopub.status.idle": "2026-08-14T20:52:32.310524Z",
     "shell.execute_reply": "2026-08-14T20:52:32.309998Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Курс после шестиугольника: 0.0\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "for _ in range(6):\n",
    "    artist.forward(80)\n",
    "    artist.right(60)\n",
    "print(\"Курс после шестиугольника:\", artist.heading())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46c067ec",
   "metadata": {},
   "source": [
    "## Эксперимент 2\n",
    "\n",
    "Попробуйте формулу `360 / n` для треугольника (n=3) и восьмиугольника (n=8)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "db8d5675",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:32.311617Z",
     "iopub.status.busy": "2026-08-14T20:52:32.311431Z",
     "iopub.status.idle": "2026-08-14T20:52:34.091038Z",
     "shell.execute_reply": "2026-08-14T20:52:34.090552Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=3: угол поворота = 120.0°\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "n=8: угол поворота = 45.0°\n"
     ]
    }
   ],
   "source": [
    "for n in [3, 8]:\n",
    "    artist.reset()\n",
    "    ugol = 360 / n\n",
    "    for _ in range(n):\n",
    "        artist.forward(70)\n",
    "        artist.right(ugol)\n",
    "    print(f\"n={n}: угол поворота = {ugol}°\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1698ebfa",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика\n",
    "\n",
    "Нарисуйте правильный пятиугольник, используя формулу `360 / n`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "575ae149",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:34.092692Z",
     "iopub.status.busy": "2026-08-14T20:52:34.092561Z",
     "iopub.status.idle": "2026-08-14T20:52:35.052154Z",
     "shell.execute_reply": "2026-08-14T20:52:35.051458Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Пятиугольник готов, угол поворота был 72.0 градусов\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "n = 5\n",
    "ugol = 360 / n\n",
    "for _ in range(n):\n",
    "    artist.forward(90)\n",
    "    artist.right(ugol)\n",
    "print(\"Пятиугольник готов, угол поворота был\", ugol, \"градусов\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b224b3ca",
   "metadata": {},
   "source": [
    "## Проверка результата"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9a333978",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:35.053312Z",
     "iopub.status.busy": "2026-08-14T20:52:35.053189Z",
     "iopub.status.idle": "2026-08-14T20:52:35.055523Z",
     "shell.execute_reply": "2026-08-14T20:52:35.054993Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: для пятиугольника угол поворота 72°.\n"
     ]
    }
   ],
   "source": [
    "assert 360 / 5 == 72.0\n",
    "print(\"Верно: для пятиугольника угол поворота 72°.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f586bfab",
   "metadata": {},
   "source": [
    "## Дополнительная задача ★★★\n",
    "\n",
    "Напишите фигуру с n=20 сторонами — на что она похожа?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "65e5aa97",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:35.056518Z",
     "iopub.status.busy": "2026-08-14T20:52:35.056399Z",
     "iopub.status.idle": "2026-08-14T20:52:36.537199Z",
     "shell.execute_reply": "2026-08-14T20:52:36.536791Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20-угольник почти неотличим от окружности!\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "n = 20\n",
    "ugol = 360 / n\n",
    "for _ in range(n):\n",
    "    artist.forward(30)\n",
    "    artist.right(ugol)\n",
    "print(\"20-угольник почти неотличим от окружности!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36d58b94",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "3dba3277",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:52:36.538509Z",
     "iopub.status.busy": "2026-08-14T20:52:36.538359Z",
     "iopub.status.idle": "2026-08-14T20:52:36.542114Z",
     "shell.execute_reply": "2026-08-14T20:52:36.541539Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Окно Turtle закрыто.\n"
     ]
    }
   ],
   "source": [
    "screen.bye()\n",
    "print(\"Окно Turtle закрыто.\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
