plotter_experiments/globe.ipynb

122 lines
3.6 KiB
Plaintext
Raw Normal View History

2022-12-11 15:37:03 +01:00
{
"cells": [
{
"cell_type": "code",
2022-12-18 12:30:19 +01:00
"execution_count": null,
2022-12-11 15:37:03 +01:00
"metadata": {},
2022-12-18 12:30:19 +01:00
"outputs": [
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.10.8 ('venv': venv)' requires ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/home/fruchti/Projekte/Python/plotterstuff/venv/bin/python -m pip install ipykernel -U --force-reinstall'"
]
}
],
2022-12-11 15:37:03 +01:00
"source": [
"from lib import plot\n",
"import IPython\n",
"import numpy as np\n",
"from random import randint, randrange, choice as randchoice"
]
},
{
"cell_type": "code",
2022-12-18 12:30:19 +01:00
"execution_count": null,
2022-12-11 15:37:03 +01:00
"metadata": {},
"outputs": [
{
2022-12-18 12:30:19 +01:00
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mRunning cells with 'Python 3.10.8 ('venv': venv)' requires ipykernel package.\n",
"\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
"\u001b[1;31mCommand: '/home/fruchti/Projekte/Python/plotterstuff/venv/bin/python -m pip install ipykernel -U --force-reinstall'"
]
2022-12-11 15:37:03 +01:00
}
],
"source": [
"a = plot.A6_PORTRAIT\n",
"p_svg = plot.SVGPlotter('plots/globe.svg', a)\n",
"p_hpgl = plot.HPGLPlotter(a, 'plots/globe_{index}.hpgl')\n",
"p = plot.MultiPlotter()\n",
"p.register_plotter(p_svg)\n",
"p.register_plotter(p_hpgl)\n",
"dia = np.min(a.size()) * 0.75\n",
"\n",
"def transform(r, theta, phi):\n",
" x = r * np.sin(theta) * np.cos(phi)\n",
" y = r * np.sin(theta) * np.sin(phi)\n",
" z = r * np.cos(theta)\n",
" \n",
" proj = np.array([[1, 0],\n",
" [0, 0.8],\n",
" [-0.0, 1.1]])\n",
" proj /= np.linalg.norm(proj, axis=0, keepdims=True)\n",
" return dia / 2 * proj.T @ [x, y, z] + a.centre()\n",
"\n",
"p.move_to(a.bottom_left())\n",
"p.line_to(a.bottom_right())\n",
"p.line_to(a.top_right())\n",
"p.line_to(a.top_left())\n",
"p.line_to(a.bottom_left())\n",
"\n",
"p.add_layer([0, 0.3, 1, 0.5])\n",
"\n",
"theta_range = np.linspace(0, np.pi, 12)\n",
"phi_range = np.linspace(0, 2 * np.pi, 12)\n",
"phi_offset = randchoice(phi_range)\n",
"for theta in theta_range:\n",
" phi_offset += phi_range[0]\n",
" p.move_to(transform(1, theta, phi_range[0] + phi_offset))\n",
" for phi in phi_range[1:8]:\n",
" p.line_to(transform(1, theta, phi + phi_offset))\n",
"\n",
"p.add_layer([0, 0.8, 0, 0.5])\n",
"\n",
"theta_offset = randchoice(theta_range)\n",
"for phi in phi_range:\n",
" theta_offset +=theta_range[0]\n",
" p.move_to(transform(1, theta_range[0] + theta_offset, phi))\n",
" for theta in theta_range[1:9]:\n",
" p.line_to(transform(1, theta + theta_offset, phi))\n",
"\n",
"p.finalise()\n",
"\n",
"IPython.display.SVG(filename=p_svg.file_name)"
]
}
],
"metadata": {
"kernelspec": {
2022-12-18 12:30:19 +01:00
"display_name": "Python 3.10.8 ('venv': venv)",
2022-12-11 15:37:03 +01:00
"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",
2022-12-18 12:30:19 +01:00
"version": "3.10.8"
2022-12-11 15:37:03 +01:00
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
2022-12-18 12:30:19 +01:00
"hash": "4e4d30d3539929de0578bbe4ec79f6b28a071ba9812633f0cffbdd386797307b"
2022-12-11 15:37:03 +01:00
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}