{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reference as the documentation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
" %matplotlib widget"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pysketcher import *"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"drawing_tool.set_coordinate_system(xmin=-10, xmax=10,ymin=-10, ymax=10,axis=True)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import SVG, display"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extra steps for YAML"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"head = \"\"\"\\\n",
"libraries: [\"from math import tan, radians, sin, cos\",\"from pysketcher import *\"]\n",
"\"\"\"\n",
"myfig={}\n",
"sketchParse(head,myfig)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Canvas"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "390b26ffd93247c3a2e588dd479b623e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.mpl.gcf().canvas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Line"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"line=\"\"\"\n",
"A: point(-5,-5)\n",
"B: point(5,5)\n",
"line: Line(A,B)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(line,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['line'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"A = point(-5,-5)\n",
"B = point(5,5)\n",
"line = Line(A,B)\n",
"line.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Rectangle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"rectangle=\"\"\"\n",
"L: 8\n",
"h: 5\n",
"p: point(-(L/2),-(h/2))\n",
"rectangle: Rectangle(p,L,h)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(rectangle,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['rectangle'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"L = 8\n",
"h = 5\n",
"p = point(-(L/2),-(h/2))\n",
"rectangle = Rectangle(p,L,h)\n",
"rectangle.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Circle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"circle=\"\"\"\n",
"circle: Circle(point(0,0),5)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(circle,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['circle'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"circle = Circle(point(0,0),5)\n",
"circle.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}