{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e4f43ca1",
   "metadata": {},
   "source": [
    "# 12-05 · Сложная мандала\n",
    "\n",
    "Практика к разделу [«Проект 12-5»](../../site/chapters/glava-12/12-05-slozhnaya-mandala.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8aee43ad",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Полностью автоматизированная мандала со случайными цветами."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21b042f7",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4e7887e9",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:40:49.499267Z",
     "iopub.status.busy": "2026-08-17T16:40:49.499162Z",
     "iopub.status.idle": "2026-08-17T16:40:49.659889Z",
     "shell.execute_reply": "2026-08-17T16:40:49.659287Z"
    }
   },
   "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": "c8d21b56",
   "metadata": {},
   "source": [
    "## Рабочий пример"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9c95870d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:40:49.660929Z",
     "iopub.status.busy": "2026-08-17T16:40:49.660819Z",
     "iopub.status.idle": "2026-08-17T16:41:25.436027Z",
     "shell.execute_reply": "2026-08-17T16:41:25.435378Z"
    }
   },
   "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": "2b11f1fa",
   "metadata": {},
   "source": [
    "## Задание ★★ Самостоятельная задача\n",
    "\n",
    "Измените `luchi` на 12 — реже расставленные лучи, но тот же принцип."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "91c49596",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:41:25.437272Z",
     "iopub.status.busy": "2026-08-17T16:41:25.437151Z",
     "iopub.status.idle": "2026-08-17T16:41:37.538873Z",
     "shell.execute_reply": "2026-08-17T16:41:37.538397Z"
    }
   },
   "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": "aad0b353",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7972fee2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T16:41:37.540007Z",
     "iopub.status.busy": "2026-08-17T16:41:37.539900Z",
     "iopub.status.idle": "2026-08-17T16:41:37.542627Z",
     "shell.execute_reply": "2026-08-17T16:41:37.542272Z"
    }
   },
   "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
}
