{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4c2bd0ff",
   "metadata": {},
   "source": [
    "# 20-17 · Surface\n",
    "\n",
    "Praktyka do sekcji [„Surface: powierzchni dla obrazu i ramy”"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef590a0f",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Utworzenie dodatkowych Surface i zastosowanie ich na ekranie po blit()."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9646f156",
   "metadata": {},
   "source": [
    "## Sprawa robocza"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3be357fa",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:13.383774Z",
     "iopub.status.busy": "2026-09-03T10:12:13.383660Z",
     "iopub.status.idle": "2026-09-03T10:12:13.565228Z",
     "shell.execute_reply": "2026-09-03T10:12:13.564797Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pygame-ce 2.5.8 (SDL 2.32.10, Python 3.14.6)\n",
      "Цвет в углу спрайта на экране: Color(255, 100, 100, 255)\n",
      "Цвет вне спрайта: Color(20, 20, 40, 255)\n"
     ]
    }
   ],
   "source": [
    "import pygame\n",
    "\n",
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "\n",
    "sprajt = pygame.Surface((100, 100))\n",
    "sprajt.fill((255, 100, 100))\n",
    "screen.fill((20, 20, 40))\n",
    "screen.blit(sprajt, (50, 50))\n",
    "pygame.display.flip()\n",
    "\n",
    "print(\"Цвет в углу спрайта на экране:\", screen.get_at((60, 60)))\n",
    "print(\"Цвет вне спрайта:\", screen.get_at((10, 10)))\n",
    "pygame.quit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8db7634",
   "metadata": {},
   "source": [
    "## Sprawdzenie wyniku"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "710dd35c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:13.570287Z",
     "iopub.status.busy": "2026-09-03T10:12:13.569993Z",
     "iopub.status.idle": "2026-09-03T10:12:13.677735Z",
     "shell.execute_reply": "2026-09-03T10:12:13.677218Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Верно: Surface нанесена через blit() ровно в указанной точке.\n"
     ]
    }
   ],
   "source": [
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "sprajt = pygame.Surface((100, 100))\n",
    "sprajt.fill((255, 100, 100))\n",
    "screen.fill((20, 20, 40))\n",
    "screen.blit(sprajt, (50, 50))\n",
    "pygame.display.flip()\n",
    "\n",
    "assert screen.get_at((60, 60))[:3] == (255, 100, 100)\n",
    "assert screen.get_at((10, 10))[:3] == (20, 20, 40)\n",
    "print(\"Верно: Surface нанесена через blit() ровно в указанной точке.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9aacce5",
   "metadata": {},
   "source": [
    "## Zadanie niezależne od zadania ★★\n",
    "\n",
    "Stwórz Surface z flagą pygame.SRCALPHA i wypełnij go półprzezroczystym kolorem (czwarta liczba w krotkach kolorowych to kanał alfa, 0-255). Nałóż go na kolorowe tło i upewnij się, że ostateczny kolor to mieszanka tła i półprzezroczystej warstwy, a nie czysty kolor samej warstwy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "d882acdc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-09-03T10:12:13.679315Z",
     "iopub.status.busy": "2026-09-03T10:12:13.679185Z",
     "iopub.status.idle": "2026-09-03T10:12:13.718207Z",
     "shell.execute_reply": "2026-09-03T10:12:13.717607Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Итоговый цвет смеси: (128, 0, 0)\n",
      "Верно: результат — смесь фона и полупрозрачного слоя.\n"
     ]
    }
   ],
   "source": [
    "pygame.init()\n",
    "screen = pygame.display.set_mode((600, 400))\n",
    "screen.fill((0, 0, 0))\n",
    "\n",
    "sloj = pygame.Surface((100, 100), pygame.SRCALPHA)\n",
    "sloj.fill((255, 0, 0, 128))  # красный с прозрачностью 50%\n",
    "screen.blit(sloj, (0, 0))\n",
    "pygame.display.flip()\n",
    "\n",
    "cvet = screen.get_at((10, 10))[:3]\n",
    "print(\"Итоговый цвет смеси:\", cvet)\n",
    "assert cvet != (255, 0, 0)  # не чистый красный — значит, прозрачность реально сработала\n",
    "assert cvet != (0, 0, 0)    # и не чистый чёрный фон\n",
    "print(\"Верно: результат — смесь фона и полупрозрачного слоя.\")"
   ]
  }
 ],
 "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
}
