{ "cells": [ { "cell_type": "markdown", "id": "3e7c0493", "metadata": {}, "source": [ "# Text\n", "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/VirtualBrainLab/urchin-examples/blob/main/basics/text.ipynb)" ] }, { "cell_type": "markdown", "id": "65870f74", "metadata": {}, "source": [ "## Install Urchin\n", "\n", "Urchin is a Python package stored on PyPI, the following code needs to be run the first time you use Urchin in a Python environment. \n", "\n", "Urchin's full documentation can be found [on our website](https://virtualbrainlab.org/urchin/installation_and_use.html)." ] }, { "cell_type": "code", "execution_count": null, "id": "365923a6", "metadata": {}, "outputs": [], "source": [ "#Installing urchin\n", "!pip install oursin -U" ] }, { "cell_type": "markdown", "id": "ffccfa79-9e51-4159-a8e3-4d38e0d69cd2", "metadata": {}, "source": [ "## Setup Urchin and open the renderer webpage \n", "\n", "By default Urchin opens the 3D renderer in a webpage. Make sure pop-ups are enabled, or the page won't open properly. You can also open the renderer site yourself by replacing [ID here] with the ID that is output by the call to `.setup()` at https://data.virtualbrainlab.org/Urchin/?ID=[ID here]\n", "\n", "Note that Urchin communicates to the renderer webpage through an internet connection, we don't currently support offline use (we hope to add support in the future)." ] }, { "cell_type": "code", "execution_count": 2, "id": "76973a23-f3a2-4932-85d7-c9a1554ec240", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(URN) connected to server\n", "Login sent with ID: test, copy this ID into the renderer to connect.\n" ] } ], "source": [ "#Importing necessary libraries:\n", "import oursin as urchin\n", "urchin.setup(id='test')" ] }, { "cell_type": "markdown", "id": "ff12b0c7", "metadata": {}, "source": [ "## How to create text\n", "To create a group of texts, call the `urchin.text.create(n)` function, passing the number of texts as a parameter. The create function returns a list of texts objects, which can then be passed to the singular functions to set the position, color, size (etc) each text individually. The individual objects can then be accessed by list index, ex: `text_liist[i]`" ] }, { "cell_type": "code", "execution_count": 3, "id": "f2545933-e1d8-47bb-aa5e-6285324e02ca", "metadata": {}, "outputs": [], "source": [ "text_list = urchin.text.create(5) #Creating list of 5 text objects" ] }, { "cell_type": "code", "execution_count": 4, "id": "633e794b", "metadata": {}, "outputs": [], "source": [ "#Sets the text of each object within the list\n", "urchin.text.set_texts(text_list, ['top left','bottom left','top right','bottom right','center'])\n", "#Sets the positions of the text objects within the list using a 2D coordinate system\n", "urchin.text.set_positions(text_list, [[-1,1], [-1, -0.9], [0.85, 1], [0.85, -0.9], [0,0]])\n", "#Sets the font sizes and colors of the text objects\n", "urchin.text.set_font_sizes(text_list, 24) # note that single values used in plural functions will be propagated out to the length of the list\n", "urchin.text.set_colors(text_list, \"#000000\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "9ac44a3f-fccd-4205-aa93-24259f521dfc", "metadata": {}, "outputs": [], "source": [ "#Changing top left text to red\n", "text_list[0].set_color([1, 0, 0])" ] }, { "cell_type": "code", "execution_count": 6, "id": "2e31c5aa-ee7e-47d9-bfd7-3c69e55c86da", "metadata": {}, "outputs": [], "source": [ "#Changing size of bottom left text \n", "text_list[1].set_font_size(100)" ] }, { "cell_type": "markdown", "id": "f66b0a21", "metadata": {}, "source": [ "Note that text annotations can't currently be capture by screenshots. We're working on it!" ] }, { "cell_type": "markdown", "id": "b70f6ff9", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "iblenv", "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.11.5" }, "vscode": { "interpreter": { "hash": "e571d860348ccccbb87c9afaea3b8de5dc8c1513265a6c0fcfe6ac69a4d3ce4b" } } }, "nbformat": 4, "nbformat_minor": 5 }