{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "cff89292",
   "metadata": {},
   "source": [
    "# 12-05 · Сложная мандала\n",
    "\n",
    "Практика к разделу [«Проект 12-5»](../../site/chapters/glava-12/12-05-slozhnaya-mandala.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f4c70248",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Полностью автоматизированная мандала со случайными цветами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a26b72f",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "29f490f0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:57:42.430003Z",
     "iopub.status.busy": "2026-08-14T20:57:42.429852Z",
     "iopub.status.idle": "2026-08-14T20:57:42.595849Z",
     "shell.execute_reply": "2026-08-14T20:57:42.595444Z"
    }
   },
   "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": "c0eebf20",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "333742a7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:57:42.597020Z",
     "iopub.status.busy": "2026-08-14T20:57:42.596893Z",
     "iopub.status.idle": "2026-08-14T20:58:18.205152Z",
     "shell.execute_reply": "2026-08-14T20:58:18.204734Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Мандала готова, лучей: 36\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "artist.reset()\n",
    "luchi = 36\n",
    "shag_ugla = 360 / luchi\n",
    "cveta = [\"red\", \"orange\", \"purple\", \"blue\", \"green\"]\n",
    "\n",
    "for i in range(luchi):\n",
    "    artist.pencolor(random.choice(cveta))\n",
    "    artist.setheading(i * shag_ugla)\n",
    "    artist.forward(150)\n",
    "    artist.circle(20)\n",
    "    artist.forward(-150)\n",
    "\n",
    "print(\"Мандала готова, лучей:\", luchi)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f38eb797",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Измените `luchi` на 12 — реже расставленные лучи, но тот же принцип."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "70691e2e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:18.206176Z",
     "iopub.status.busy": "2026-08-14T20:58:18.206061Z",
     "iopub.status.idle": "2026-08-14T20:58:30.214918Z",
     "shell.execute_reply": "2026-08-14T20:58:30.214374Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luchi=12: готово\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "artist.reset()\n",
    "luchi = 12\n",
    "shag_ugla = 360 / luchi\n",
    "cveta = [\"red\", \"orange\", \"purple\", \"blue\", \"green\"]\n",
    "for i in range(luchi):\n",
    "    artist.pencolor(random.choice(cveta))\n",
    "    artist.setheading(i * shag_ugla)\n",
    "    artist.forward(150)\n",
    "    artist.circle(20)\n",
    "    artist.forward(-150)\n",
    "print(f\"luchi={luchi}: готово\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ed9be38",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ae1a24e6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-14T20:58:30.215932Z",
     "iopub.status.busy": "2026-08-14T20:58:30.215809Z",
     "iopub.status.idle": "2026-08-14T20:58:30.219132Z",
     "shell.execute_reply": "2026-08-14T20:58:30.218677Z"
    }
   },
   "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
}
