You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
184 lines
8.0 KiB
Plaintext
184 lines
8.0 KiB
Plaintext
3 years ago
|
{
|
||
|
"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": [
|
||
|
"<svg baseProfile=\"tiny\" height=\"100%\" version=\"1.2\" width=\"100%\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs/><line stroke=\"rgb(10%,10%,16%)\" x1=\"0\" x2=\"10\" y1=\"0\" y2=\"50\"/><text x=\"0\" y=\"0.2\">Test</text></svg>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
"<IPython.core.display.SVG object>"
|
||
|
]
|
||
|
},
|
||
|
"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": [
|
||
|
"<svg baseProfile=\"tiny\" height=\"297mm\" version=\"1.2\" width=\"210mm\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"><defs/><g id=\"grid\" stroke=\"dodgerblue\" stroke-dasharray=\"5 5\"><line x1=\"0\" x2=\"210mm\" y1=\"0.0mm\" y2=\"0.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"49.5mm\" y2=\"49.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"99.0mm\" y2=\"99.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"148.5mm\" y2=\"148.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"198.0mm\" y2=\"198.0mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"247.5mm\" y2=\"247.5mm\"/><line x1=\"0\" x2=\"210mm\" y1=\"297.0mm\" y2=\"297.0mm\"/><line x1=\"0.0mm\" x2=\"0.0mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"52.5mm\" x2=\"52.5mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"105.0mm\" x2=\"105.0mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"157.5mm\" x2=\"157.5mm\" y1=\"0\" y2=\"297mm\"/><line x1=\"210.0mm\" x2=\"210.0mm\" y1=\"0\" y2=\"297mm\"/></g><g id=\"placeholders\" stroke=\"black\"><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"49.5mm\" y=\"52.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"198.0mm\" y=\"52.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"0.0mm\" y=\"105.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"49.5mm\" y=\"105.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"99.0mm\" y=\"105.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"148.5mm\" y=\"105.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"49.5mm\" y=\"157.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"148.5mm\" y=\"157.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"198.0mm\" y=\"157.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"0.0mm\" y=\"210.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"49.5mm\" y=\"210.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"148.5mm\" y=\"210.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"0.0mm\" y=\"262.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"198.0mm\" y=\"262.5mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"0.0mm\" y=\"315.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"49.5mm\" y=\"315.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"99.0mm\" y=\"315.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"148.5mm\" y=\"315.0mm\"/><rect fill=\"none\" height=\"50mm\" stroke=\"rgb(0%,0%,0%)\" width=\"50mm\" x=\"198.0mm\" y=\"315.0mm\"/></g></svg>"
|
||
|
],
|
||
|
"text/plain": [
|
||
|
"<IPython.core.display.SVG object>"
|
||
|
]
|
||
|
},
|
||
|
"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
|
||
|
}
|