{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3028fc95",
   "metadata": {},
   "source": [
    "# 10-19 · Случайное блуждание и звёздное поле\n",
    "\n",
    "Практика к разделу [«Случайные узоры»](../../site/chapters/glava-10/10-14-sluchajnye-uzory.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9dc46d2e",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Соединить циклы со случайностью — с фиксированным seed() для воспроизводимости."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "335a7319",
   "metadata": {},
   "source": [
    "## Настройка (выполнить один раз)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8aedd1a4",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:15:27.187705Z",
     "iopub.status.busy": "2026-08-16T20:15:27.187589Z",
     "iopub.status.idle": "2026-08-16T20:15:27.365037Z",
     "shell.execute_reply": "2026-08-16T20:15:27.364579Z"
    }
   },
   "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": "a9cc1d6b",
   "metadata": {},
   "source": [
    "## Рабочий пример — случайное блуждание"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "aa2321ab",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:15:27.366098Z",
     "iopub.status.busy": "2026-08-16T20:15:27.365987Z",
     "iopub.status.idle": "2026-08-16T20:15:40.958370Z",
     "shell.execute_reply": "2026-08-16T20:15:40.958033Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Блуждание готово.\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "artist.reset()\n",
    "random.seed(7)\n",
    "\n",
    "for _ in range(100):\n",
    "    artist.setheading(random.randint(0, 360))\n",
    "    artist.forward(10)\n",
    "print(\"Блуждание готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83debdd6",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика — звёздное поле"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8659a696",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:15:40.959585Z",
     "iopub.status.busy": "2026-08-16T20:15:40.959472Z",
     "iopub.status.idle": "2026-08-16T20:15:54.070238Z",
     "shell.execute_reply": "2026-08-16T20:15:54.069686Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Звёздное поле готово.\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "artist.reset()\n",
    "artist.hideturtle()\n",
    "artist.penup()\n",
    "random.seed(3)\n",
    "\n",
    "for _ in range(60):\n",
    "    x = random.randint(-190, 190)\n",
    "    y = random.randint(-190, 190)\n",
    "    artist.goto(x, y)\n",
    "    artist.dot(6, \"white\")\n",
    "print(\"Звёздное поле готово.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eaae13fe",
   "metadata": {},
   "source": [
    "## Завершение (выполнить один раз, в самом конце)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c199fa95",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-16T20:15:54.071637Z",
     "iopub.status.busy": "2026-08-16T20:15:54.071477Z",
     "iopub.status.idle": "2026-08-16T20:15:54.076582Z",
     "shell.execute_reply": "2026-08-16T20:15:54.075562Z"
    }
   },
   "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
}
