{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "bc342129",
   "metadata": {},
   "source": [
    "# 20-15 · FPS i budżet\n",
    "\n",
    "Praktyka do sekcji [„Klatki na sekundę i czas klatki”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "69f8e1e5",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Odczytaj czas klatki z FPS i z powrotem, bez żadnego wywołania Pygame."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c4916626",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "999528e6",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:08.475713Z",
     "iopub.status.busy": "2026-09-03T10:12:08.475540Z",
     "iopub.status.idle": "2026-09-03T10:12:08.506195Z",
     "shell.execute_reply": "2026-09-03T10:12:08.505593Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "30 FPS -> 33.333 мс на кадр\n",
      "60 FPS -> 16.667 мс на кадр\n",
      "120 FPS -> 8.333 мс на кадр\n",
      "120 мс на кадр соответствуют 8.33 FPS\n"
     ]
    }
   ],
   "source": [
    "def vremya_kadra_ms(fps):\n",
    "    return 1000 / fps\n",
    "\n",
    "def fps_iz_vremeni_kadra(vremya_ms):\n",
    "    return 1000 / vremya_ms\n",
    "\n",
    "for fps in (30, 60, 120):\n",
    "    print(f\"{fps} FPS -> {vremya_kadra_ms(fps):.3f} мс на кадр\")\n",
    "\n",
    "print(\"120 мс на кадр соответствуют\", round(fps_iz_vremeni_kadra(120), 2), \"FPS\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ee817074",
   "metadata": {},
   "source": [
    "## Sprawdzenie wyniku"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a79f6adc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:08.507885Z",
     "iopub.status.busy": "2026-09-03T10:12:08.507708Z",
     "iopub.status.idle": "2026-09-03T10:12:08.511818Z",
     "shell.execute_reply": "2026-09-03T10:12:08.511175Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: время кадра и FPS — взаимно обратные величины.\n"
     ]
    }
   ],
   "source": [
    "assert round(vremya_kadra_ms(60), 3) == 16.667\n",
    "assert round(vremya_kadra_ms(30), 3) == 33.333\n",
    "assert round(fps_iz_vremeni_kadra(20), 1) == 50.0\n",
    "print(\"Верно: время кадра и FPS — взаимно обратные величины.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b87a8c49",
   "metadata": {},
   "source": [
    "## Podstawowa praktyka zadań ★\n",
    "\n",
    "Zdefiniuj funkcję skolko_kadrov_za_sekundy(fps sekund), która zwraca całkowitą liczbę klatek, które przejdą w określonym czasie."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "b136f08b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:08.515996Z",
     "iopub.status.busy": "2026-09-03T10:12:08.515789Z",
     "iopub.status.idle": "2026-09-03T10:12:08.519925Z",
     "shell.execute_reply": "2026-09-03T10:12:08.519418Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "За 2.5 секунды на 24 FPS пройдёт 60 кадров\n"
     ]
    }
   ],
   "source": [
    "def skolko_kadrov_za_sekundy(fps, sekund):\n",
    "    return int(fps * sekund)\n",
    "\n",
    "assert skolko_kadrov_za_sekundy(60, 2) == 120\n",
    "assert skolko_kadrov_za_sekundy(30, 0.5) == 15\n",
    "print(\"За 2.5 секунды на 24 FPS пройдёт\", skolko_kadrov_za_sekundy(24, 2.5), \"кадров\")"
   ]
  }
 ],
 "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
}
