Skip to content

Commit

Permalink
Simple example of SVG rendering using duality example.
Browse files Browse the repository at this point in the history
  • Loading branch information
tBuLi committed Jul 5, 2024
1 parent 4b9b813 commit 383641c
Showing 1 changed file with 139 additions and 0 deletions.
139 changes: 139 additions & 0 deletions content/2DPGA/ex_2dpga_dual.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "2dc7b21b-034b-42e9-ad83-05d9605de074",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install -q kingdon anywidget==0.9.9"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ebb1e69c-7bb1-4eeb-a6a0-dbf06c76c4d4",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from kingdon import Algebra\n",
"import ipywidgets"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "0d34bcef-2f02-49ff-955a-87fd3d694147",
"metadata": {},
"outputs": [],
"source": [
"alg = Algebra(2, 0, 1)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0ffd82d4-cfba-41e5-879e-f9ad4e284f20",
"metadata": {},
"outputs": [],
"source": [
"thetas = np.linspace(0, 2 * np.pi, 3, endpoint=False)\n",
"x = np.cos(thetas)\n",
"y = np.sin(thetas)\n",
"w = np.ones_like(x)\n",
"lines = alg.vector(e0=w, e1=x, e2=y)\n",
"points = lines.dual()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "9a395761-71f5-4854-aaf0-b675d922f3d0",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "616331cc426249d58f6f94665ec8daf0",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(FloatSlider(value=0.0, max=1.0), GraphWidget(cayley=[['1', 'e0', 'e1', 'e2', 'e01', 'e02', 'e12…"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def graph_func():\n",
" return [\n",
" f'<G fill-opacity={str(1.0 - slider.value)}>',\n",
" points,\n",
" '</G>',\n",
" f'<G stroke-opacity={slider.value}>',\n",
" lines,\n",
" '</G>',\n",
" ]\n",
"\n",
"slider = ipywidgets.FloatSlider(\n",
" value=0.0,\n",
" min=0.0,\n",
" max=1.0,\n",
" continuous_update=True,\n",
")\n",
"\n",
"graph = alg.graph(\n",
" graph_func,\n",
" animate=True,\n",
" width='100%',\n",
" scale=0.5,\n",
" lineWidth=6,\n",
")\n",
"\n",
"ipywidgets.VBox([slider, graph])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bfac1ff2-0180-40b4-ac7e-2b63834811ca",
"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.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 383641c

Please sign in to comment.