{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "# Tutorial 2" ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "from tikzpics import TikzFigure" ] }, { "cell_type": "code", "execution_count": null, "id": "3", "metadata": {}, "outputs": [], "source": [ "fig = TikzFigure()\n", "\n", "options = [\"draw\", \"rounded corners=8pt\", \"line width=6\"]\n", "colors = [\"purple\", \"blue\", \"purple\"]\n", "\n", "# M with thick tracing\n", "nodes_M = [\n", " [0, 0],\n", " [0, 3.5],\n", " [1, 3.5],\n", " [1.25, 2.75],\n", " [1.5, 3.5],\n", " [2.5, 3.5],\n", " [2.5, 0],\n", " [2, 0],\n", " [2, 2.75],\n", " [1.25, 2.0],\n", " [0.5, 2.75],\n", " [0.5, 0],\n", "]\n", "\n", "fig.draw(\n", " nodes_M,\n", " options=options,\n", " layer=0,\n", " cycle=True,\n", " color=colors[0],\n", " fill=f\"{colors[0]}!50!white\",\n", " comment=\"Path for M\",\n", ")\n", "\n", "# T with thick tracing\n", "nodes_T = [\n", " [3.125, 0],\n", " [3.125, 4],\n", " [0, 4],\n", " [0, 4.75],\n", " [7, 4.75],\n", " [7, 4],\n", " [3.875, 4],\n", " [3.875, 0],\n", "]\n", "\n", "fig.draw(\n", " nodes_T,\n", " options=options,\n", " layer=0,\n", " cycle=True,\n", " color=colors[1],\n", " fill=f\"{colors[1]}!50!white\",\n", " comment=\"Path for T\",\n", ")\n", "\n", "# L with thick tracing\n", "nodes_L = [\n", " [4.5, 0],\n", " [4.5, 3.5],\n", " [5.25, 3.5],\n", " [5.25, 0.75],\n", " [7, 0.75],\n", " [7, 0],\n", "]\n", "\n", "fig.draw(\n", " nodes_L,\n", " options=options,\n", " layer=2,\n", " cycle=True,\n", " color=colors[2],\n", " fill=f\"{colors[2]}!50!white\",\n", " comment=\"Path for L\",\n", ")\n", "\n", "xvec = np.arange(0, 7, 0.1)\n", "yvec = np.sin(xvec) * 0.25 + 1.25\n", "\n", "nodes_line = [(x, y) for x, y in zip(xvec, yvec)]\n", "\n", "fig.draw(\n", " nodes_line,\n", " options=options,\n", " layer=1,\n", " color=\"black\",\n", " comment=\"Sine wave path\",\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "# Print the tikz code\n", "print(fig.generate_tikz())" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.13.3" } }, "nbformat": 4, "nbformat_minor": 5 }