{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0a4cdc2a",
   "metadata": {},
   "source": [
    "# 13-08 · Фигуры: новый уровень\n",
    "\n",
    "Практика к разделу [«Мини-проект — автоматизированные фигуры: новый уровень»](../../site/chapters/glava-13/13-08-mini-proekt-figury-itogi.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ae7431bc",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Превратить рисование фигур в переиспользуемую функцию."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "781a792c",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4d5868e6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:40.938833Z",
     "iopub.status.busy": "2026-08-14T20:58:40.938730Z",
     "iopub.status.idle": "2026-08-14T20:58:41.117337Z",
     "shell.execute_reply": "2026-08-14T20:58:41.116855Z"
    }
   },
   "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": "03755914",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "be74bc2d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:41.118342Z",
     "iopub.status.busy": "2026-08-14T20:58:41.118227Z",
     "iopub.status.idle": "2026-08-14T20:58:42.016031Z",
     "shell.execute_reply": "2026-08-14T20:58:42.015639Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Квадрат готов.\n"
     ]
    }
   ],
   "source": [
    "def narisovat_figuru(storony, dlina):\n",
    "    ugol = 360 / storony\n",
    "    for _ in range(storony):\n",
    "        artist.forward(dlina)\n",
    "        artist.right(ugol)\n",
    "\n",
    "artist.reset()\n",
    "narisovat_figuru(4, 100)\n",
    "print(\"Квадрат готов.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad061f8f",
   "metadata": {},
   "source": [
    "## Эксперимент 1 — несколько фигур подряд"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "02e15d3a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:42.017251Z",
     "iopub.status.busy": "2026-08-14T20:58:42.017135Z",
     "iopub.status.idle": "2026-08-14T20:58:43.891438Z",
     "shell.execute_reply": "2026-08-14T20:58:43.891087Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Треугольник готов.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Восьмиугольник готов.\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "narisovat_figuru(3, 100)\n",
    "print(\"Треугольник готов.\")\n",
    "\n",
    "artist.reset()\n",
    "narisovat_figuru(8, 60)\n",
    "print(\"Восьмиугольник готов.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56a08ef3",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Добавьте параметры x, y со значениями по умолчанию 0, 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1880e033",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:43.892815Z",
     "iopub.status.busy": "2026-08-14T20:58:43.892670Z",
     "iopub.status.idle": "2026-08-14T20:58:45.890812Z",
     "shell.execute_reply": "2026-08-14T20:58:45.890099Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Две фигуры в разных точках экрана готовы.\n"
     ]
    }
   ],
   "source": [
    "def narisovat_figuru_v_tochke(storony, dlina, x=0, y=0):\n",
    "    artist.penup()\n",
    "    artist.goto(x, y)\n",
    "    artist.setheading(0)\n",
    "    artist.pendown()\n",
    "    ugol = 360 / storony\n",
    "    for _ in range(storony):\n",
    "        artist.forward(dlina)\n",
    "        artist.right(ugol)\n",
    "\n",
    "artist.reset()\n",
    "narisovat_figuru_v_tochke(4, 60, x=-100, y=0)\n",
    "narisovat_figuru_v_tochke(6, 60, x=100, y=0)\n",
    "print(\"Две фигуры в разных точках экрана готовы.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bca1a1cb",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8054a637",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:45.892687Z",
     "iopub.status.busy": "2026-08-14T20:58:45.892527Z",
     "iopub.status.idle": "2026-08-14T20:58:45.897350Z",
     "shell.execute_reply": "2026-08-14T20:58:45.896854Z"
    }
   },
   "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
}
