plotter_experiments/globe.ipynb

112 lines
12 KiB
Plaintext
Raw Normal View History

2022-12-11 15:37:03 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"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",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"297.637795pt\" height=\"419.527559pt\" viewBox=\"0 0 297.637795 419.527559\" version=\"1.1\">\n<g id=\"surface6\">\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 7.999512 7.999512 L 97.000109 7.999512 L 97.000109 140.000412 L 7.999512 140.000412 L 7.999512 7.999512 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 52.500499 100.990907 L 52.500499 100.990907 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 61.902854 99.898123 L 60.410438 102.888466 L 56.405859 104.92934 L 51.162424 105.373069 L 46.342046 104.077713 L 43.478483 101.456684 L 43.478483 98.339562 L 46.342046 95.718533 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 70.544531 96.706586 L 67.67959 102.444737 L 59.995649 106.361122 L 49.931836 107.211372 L 40.683822 104.726769 L 35.186827 99.696929 L 35.186827 93.716243 L 40.683822 88.686404 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 77.722732 91.675369 L 73.719531 99.696929 L 62.977724 105.170497 L 48.91071 106.359744 L 35.981955 102.887088 L 28.298014 95.854959 L 28.298014 87.495779 L 35.981955 80.46365 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 82.858681 85.21237 L 78.039681 94.866905 L 65.110927 101.455306 L 48.178971 102.887088 L 32.619542 98.707498 L 23.37015 90.243587 L 23.37015 80.18253 L 32.619542 71.717242 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 85.534831 77.841243 L 80.291395 88.346029 L 66.223003 95.515961 L 47.798633 97.074523 L 30.866678 92.525618 L 20.802865 83.314811 L 20.802865 72.367676 L 30.866678 63.156868 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 85.534831 70.158681 L 80.291395 80.663466 L 66.223003 87.833398 L 47.798633 89.39196 L 30.866678 84.843056 L 20.802865 75.632248 L 20.802865 64.685113 L 30.866678 55.474306 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 82.858681 62.787554 L 78.039681 72.440712 L 65.110927 79.03049 L 48.178971 80.462272 L 32.619542 76.282682 L 23.37015 67.817394 L 23.37015 57.756337 L 32.619542 49.292426 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 77.722732 56.324555 L 73.719531 64.344737 L 62.977724 69.819683 L 48.91071 71.00893 L 35.981955 67.536274 L 28.298014 60.504145 L 28.298014 52.144965 L 35.981955 45.112836 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 70.544531 51.293338 L 67.67959 57.031489 L 59.995649 60.94
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"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": {
"display_name": "Python 3.9.15 64-bit",
"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.9.15"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "1dc4d77b1edb83bef89f833b7ed5251134c6a4899ef5e2c90c44e9927b4ae63a"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}