{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "68a8ec84-7d7a-4145-92ca-e35bae9ffe92", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple\n", "Collecting svgwrite\n", " Downloading https://www.piwheels.org/simple/svgwrite/svgwrite-1.4.1-py3-none-any.whl (66 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.0/67.0 KB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hInstalling collected packages: svgwrite\n", "Successfully installed svgwrite-1.4.1\n" ] } ], "source": [ "!pip install svgwrite" ] }, { "cell_type": "code", "execution_count": 9, "id": "4d5a776b-5e07-498d-ade3-310bd5d29b22", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "Test" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import svgwrite\n", "from IPython.core.display import SVG, display\n", "\n", "dwg = svgwrite.Drawing('test.svg', profile='tiny', size=(595, 842) )\n", "dwg.add(dwg.line((0, 0), (10, 50), stroke=svgwrite.rgb(10, 10, 16, '%')))\n", "dwg.add(dwg.text('Test', insert=(0, 0.2)))\n", "dwg.save()\n", "\n", "display(SVG(filename=f'test.svg'))" ] }, { "cell_type": "code", "execution_count": 102, "id": "93b6030a-22e5-44a8-b261-26d64112eb92", "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import svgwrite\n", "from svgwrite import cm, mm\n", "\n", "import random\n", "\n", "# We are using real world sizes in order to match with the post-it placeholders \n", "\n", "debug = True\n", "\n", "width = 210\n", "height = 297\n", "\n", "rows = 6\n", "columns = 4\n", "\n", "cell_size = (width/columns, height/rows)\n", "\n", "color = svgwrite.rgb(0,0,0, '%')\n", "background = svgwrite.rgb(100,95,95,'%')\n", "\n", "\n", "# setup the SVG\n", "sheet = svgwrite.Drawing('map.svg', profile='tiny', size=(width * mm, height * mm))\n", "\n", "\n", "# draw debug helper grid\n", "if debug:\n", " grid = sheet.add(sheet.g(id='grid', stroke='dodgerblue')).dasharray([5, 5])\n", "\n", " for row in range(rows + 1):\n", " y = cell_size[1] * row \n", " grid.add(sheet.line((0, y * mm), (width * mm, y * mm)))\n", "\n", " for col in range(columns + 1):\n", " x = cell_size[0] * col\n", " grid.add(sheet.line((x * mm, 0), (x * mm,height * mm)))\n", "\n", "\n", "# defining the basic shapes\n", "\n", "def quad_post(x, y):\n", " quad_post_size = (50 * mm, 50 * mm)\n", " return svgwrite.shapes.Rect(insert=(x,y), size=quad_post_size, stroke=color, fill='none')\n", "\n", "\n", "# adding a group for the post-it placeholders\n", "placeholders = sheet.add(sheet.g(id='placeholders', stroke='black'))\n", "\n", "for row in range(rows + 1):\n", " for col in range(columns + 1):\n", " if random.random() > 0.5:\n", " placeholders.add(quad_post(col * cell_size[1] * mm, row * cell_size[0] * mm))\n", " \n", " \n", " \n", "sheet.save()\n", "display(SVG(filename=f'map.svg'))" ] }, { "cell_type": "code", "execution_count": null, "id": "0e573286-ef9e-42ac-a0e7-2981849a5662", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "5c2e2b89-9e63-4a58-a8a2-65e589d0432b", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "f0e007c0-1eba-4a80-b91f-79efcb34442f", "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.7.3" } }, "nbformat": 4, "nbformat_minor": 5 }