{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0edbdd47",
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pynsn'",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpynsn\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m      2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpynsn\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mimage\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m pil_image\n",
      "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pynsn'"
     ]
    }
   ],
   "source": [
    "from pynsn import *\n",
    "from pynsn.image import pil_image"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b378b7a",
   "metadata": {},
   "source": [
    "To generate a random nsn stimulus, you have to define\n",
    "\n",
    "1. an NSN factory\n",
    "2. a distribution for the object size "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e064fd3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Generate random nsn stimulus with 15 dots\n",
    "stim = NSNStimulus(target_area_shape=Dot(300))\n",
    "stim.add_shapes(Dot(diameter=20, attribute=\"darkgreen\"), n=12, random_position=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2d681101",
   "metadata": {},
   "source": [
    "Make picture of the stimulus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3ee3b63c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 26320 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=300x300>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pil_image.create(stim)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4179c800",
   "metadata": {},
   "source": [
    "## Adapting Stimulus Colour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "17da0115",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 34220 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=300x300>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stim.colours.target_area=\"#FFF0D9\"\n",
    "stim.colours.convex_hull=\"red\"\n",
    "stim.colours.center_of_mass=\"lightblue\"\n",
    "stim.colours.center_of_field_area=\"lightgreen\"\n",
    "stim.colours.background=\"#3D3D3D\"\n",
    "\n",
    "pil_image.create(stim)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db9d290e",
   "metadata": {},
   "source": [
    "## Incremental "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0969029a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 5388 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 5540 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 5740 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 5852 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 5956 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 6052 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 6308 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 6372 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 6500 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 6600 characters]\n",
      "text/plain": [
       "<PIL.Image.Image image mode=RGBA size=100x100>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "stim = NSNStimulus(target_area_shape=Dot(100, attribute=\"darkgray\"))\n",
    "for n in range(10):\n",
    "    stim.add_shapes(Rectangle(size=[9, 12], attribute=\"darkmagenta\"),random_position=True)\n",
    "    img = pil_image.create(stim)\n",
    "    display(img)\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9cb3dfbd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
