{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Reference as the documentation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Table of Content"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* [Line](#Line)\n",
"* [Rectangle](#Rectangle)\n",
"* [Triangle](#Triangle)\n",
"* [Circle](#Circle)\n",
"* [Distance with text](#Distance-with-text)\n",
"* [Text](#Text)\n",
"* [Cross](#Cross)\n",
"* [](#)\n",
"* [](#)"
]
},
{
"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": 4,
"metadata": {},
"outputs": [],
"source": [
"from IPython.display import SVG, display"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Extra steps for YAML"
]
},
{
"cell_type": "code",
"execution_count": 5,
"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": 6,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7d86c63bd11740ddaf2836b62a13ed7b",
"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": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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": 8,
"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": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 9,
"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": 10,
"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": [
"## Triangle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"triangle=\"\"\"\n",
"L: 3.0\n",
"W: 4.0\n",
"triangle: Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(tria\n",
" ngle,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['triangle'].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 = 3.0\n",
"W = 4.0\n",
"triangle = Triangle(p1=(W/2,0), p2=(3*W/2,W/2), p3=(4*W/5.,L))\n",
"triangle.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Circle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 11,
"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": 12,
"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": "markdown",
"metadata": {},
"source": [
"## Distance with text"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"dwt=\"\"\"\n",
"fontsize: 14\n",
"t: r'$ 2\\pi R^2 $' # sample text\n",
"dwt: Distance_wText((-4,0), (8, 5), t, fontsize)\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(dwt,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['dwt'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"fontsize=14\n",
"t = r'$ 2\\pi R^2 $' # sample text\n",
"dwt = Distance_wText((-4,0), (8, 5), t, fontsize)\n",
"dwt.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Text"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"text=\"\"\"\n",
"text: Text(r'$c$', point(0,0))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(text,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['text'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"text = Text(r'$c$', point(0,0))\n",
"text.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cross"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cross=\"\"\"\n",
"c: point(0,0)\n",
"l: 0.1\n",
"line1: Line(c+point(-l,l),c+point(l,-l))\n",
"line2: Line(c+point(l,l), c+point(-l,-l))\n",
"cross: \n",
" formula: \"Composition({'line1': line1, 'line2': line2})\"\n",
" style:\n",
" linecolor: black\n",
" linewidth: 1\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(cross,myfig)\n",
"d = myfig['cross'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"cross1=\"\"\"\n",
"cross1: Cross(point(0,0))\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(cross1,myfig)\n",
"d = myfig['cross1'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"drawing_tool.erase()\n",
"cross = Cross(point(1,0))\n",
"cross.draw()\n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Object"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[home](#Table-of-Content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### YAML"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "type object 'object' has no attribute 'draw'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0msketchParse\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mobject\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mmyfig\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;31m# replace 'object' by the actual one\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0md\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmyfig\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'object'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mdrawing_tool\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSVG\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msketch2SVG\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: type object 'object' has no attribute 'draw'"
]
}
],
"source": [
"object=\"\"\"\n",
"TBC:\n",
"\"\"\"\n",
"drawing_tool.erase()\n",
"sketchParse(object,myfig)\n",
"# replace 'object' by the actual one\n",
"d = myfig['object'].draw() \n",
"drawing_tool.display()\n",
"display(SVG(sketch2SVG()))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Python"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'ellipsis' object has no attribute 'draw'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;31m# put code\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mobject\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m...\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mobject\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdraw\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 5\u001b[0m \u001b[0mdrawing_tool\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[0mdisplay\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mSVG\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msketch2SVG\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mAttributeError\u001b[0m: 'ellipsis' object has no attribute 'draw'"
]
}
],
"source": [
"drawing_tool.erase()\n",
"# put code\n",
"object = ...\n",
"object.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
}