{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f86e0d46",
   "metadata": {},
   "source": [
    "# 12-03 · Рождественская ёлка\n",
    "\n",
    "Практика к разделу [«Проект 12-3»](../../site/chapters/glava-12/12-03-elka.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e5af406d",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Нарисовать ёлку из уменьшающихся треугольных ярусов."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fae6c201",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e9d00bc7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:56.593221Z",
     "iopub.status.busy": "2026-08-14T20:55:56.593029Z",
     "iopub.status.idle": "2026-08-14T20:55:56.766495Z",
     "shell.execute_reply": "2026-08-14T20:55:56.765932Z"
    }
   },
   "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": "2a9d67c4",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9cce59f5",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:55:56.767761Z",
     "iopub.status.busy": "2026-08-14T20:55:56.767629Z",
     "iopub.status.idle": "2026-08-14T20:56:00.550693Z",
     "shell.execute_reply": "2026-08-14T20:56:00.550210Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ёлка из 4 ярусов готова.\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "artist.pencolor(\"green\")\n",
    "artist.fillcolor(\"green\")\n",
    "\n",
    "yarusy = 4\n",
    "shirina = 120\n",
    "\n",
    "artist.penup()\n",
    "artist.goto(0, 100)\n",
    "artist.pendown()\n",
    "\n",
    "for yarus in range(yarusy):\n",
    "    artist.begin_fill()\n",
    "    artist.setheading(240)\n",
    "    artist.forward(shirina)\n",
    "    artist.setheading(0)\n",
    "    artist.forward(shirina)\n",
    "    artist.setheading(120)\n",
    "    artist.forward(shirina)\n",
    "    artist.end_fill()\n",
    "\n",
    "    artist.penup()\n",
    "    artist.setheading(270)\n",
    "    artist.forward(30)\n",
    "    artist.pendown()\n",
    "    shirina -= 20\n",
    "\n",
    "print(\"Ёлка из\", yarusy, \"ярусов готова.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db5c64cf",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Измените число ярусов на 6 и начальную ширину — на 150."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6ae8e8b7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:56:00.551754Z",
     "iopub.status.busy": "2026-08-14T20:56:00.551639Z",
     "iopub.status.idle": "2026-08-14T20:56:06.231070Z",
     "shell.execute_reply": "2026-08-14T20:56:06.230597Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ёлка из 6 ярусов готова.\n"
     ]
    }
   ],
   "source": [
    "artist.reset()\n",
    "artist.pencolor(\"green\")\n",
    "artist.fillcolor(\"green\")\n",
    "\n",
    "yarusy = 6\n",
    "shirina = 150\n",
    "\n",
    "artist.penup()\n",
    "artist.goto(0, 130)\n",
    "artist.pendown()\n",
    "\n",
    "for yarus in range(yarusy):\n",
    "    artist.begin_fill()\n",
    "    artist.setheading(240)\n",
    "    artist.forward(shirina)\n",
    "    artist.setheading(0)\n",
    "    artist.forward(shirina)\n",
    "    artist.setheading(120)\n",
    "    artist.forward(shirina)\n",
    "    artist.end_fill()\n",
    "\n",
    "    artist.penup()\n",
    "    artist.setheading(270)\n",
    "    artist.forward(25)\n",
    "    artist.pendown()\n",
    "    shirina -= 20\n",
    "\n",
    "print(\"Ёлка из\", yarusy, \"ярусов готова.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56f7ac01",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "390aff7c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:56:06.232331Z",
     "iopub.status.busy": "2026-08-14T20:56:06.232207Z",
     "iopub.status.idle": "2026-08-14T20:56:06.235696Z",
     "shell.execute_reply": "2026-08-14T20:56:06.235167Z"
    }
   },
   "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
}
