112 lines
12 KiB
Plaintext
112 lines
12 KiB
Plaintext
{
|
|
"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.946495 L 49.931836 61.798123 L 40.683822 59.31352 L 35.186827 54.283681 L 35.186827 48.302995 L 40.683822 43.273155 \" 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 48.101801 L 60.410438 51.092144 L 56.405859 53.133019 L 51.162424 53.575369 L 46.342046 52.281391 L 43.478483 49.660362 L 43.478483 46.54324 L 46.342046 43.922211 \" 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 47.009017 L 52.500499 47.009017 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 77.722732 56.324555 L 70.544531 51.293338 L 61.902854 48.101801 L 52.500499 47.009017 L 43.096766 48.101801 L 34.456467 51.293338 L 27.276888 56.324555 L 22.14094 62.787554 L 19.464789 70.158681 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 73.719531 64.344737 L 67.67959 57.031489 L 60.410438 51.092144 L 52.500499 47.009017 L 44.589182 45.111458 L 37.32003 45.555187 L 31.281467 48.302995 L 26.959939 53.133019 L 24.709603 59.653895 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 62.977724 69.819683 L 59.995649 60.946495 L 56.405859 53.133019 L 52.500499 47.009017 L 48.593761 43.070584 L 45.003971 41.638802 L 42.021897 42.829427 L 39.888694 46.544618 L 38.776617 52.483963 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 48.91071 71.00893 L 49.931836 61.798123 L 51.162424 53.575369 L 52.500499 47.009017 L 53.838574 42.628234 L 55.067784 40.788553 L 56.090289 41.64018 L 56.820649 45.112836 L 57.200987 50.925401 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 35.981955 67.536274 L 40.683822 59.31352 L 46.342046 52.281391 L 52.500499 47.009017 L 58.657574 43.922211 L 64.315799 43.273155 L 69.017665 45.112836 L 72.381456 49.292426 L 74.132943 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 28.298014 60.504145 L 35.186827 54.283681 L 43.478483 49.660362 L 52.500499 47.009017 L 61.522515 46.54324 L 69.812793 48.302995 L 76.701606 52.144965 L 81.62947 57.756337 L 84.196756 64.685113 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 28.298014 52.144965 L 35.186827 48.302995 L 43.478483 46.54324 L 52.500499 47.009017 L 61.522515 49.660362 L 69.812793 54.283681 L 76.701606 60.504145 L 81.62947 67.817394 L 84.196756 75.632248 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 35.981955 45.112836 L 40.683822 43.273155 L 46.342046 43.922211 L 52.500499 47.009017 L 58.657574 52.281391 L 64.315799 59.31352 L 69.017665 67.536274 L 72.381456 76.282682 L 74.132943 84.843056 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 48.91071 41.64018 L 49.931836 40.788553 L 51.162424 42.628234 L 52.500499 47.009017 L 53.838574 53.575369 L 55.067784 61.798123 L 56.090289 71.00893 L 56.820649 80.462272 L 57.200987 89.39196 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 62.977724 42.829427 L 59.995649 41.638802 L 56.405859 43.070584 L 52.500499 47.009017 L 48.593761 53.133019 L 45.003971 60.946495 L 42.021897 69.819683 L 39.888694 79.03049 L 38.776617 87.833398 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 73.719531 48.302995 L 67.67959 45.555187 L 60.410438 45.111458 L 52.500499 47.009017 L 44.589182 51.092144 L 37.32003 57.031489 L 31.281467 64.344737 L 26.959939 72.440712 L 24.709603 80.663466 \" 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%,80%,0%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 77.722732 56.324555 L 70.544531 51.293338 L 61.902854 48.101801 L 52.500499 47.009017 L 43.096766 48.101801 L 34.456467 51.293338 L 27.276888 56.324555 L 22.14094 62.787554 L 19.464789 70.158681 \" transform=\"matrix(2.834646,0,0,2.834646,0,0)\"/>\n</g>\n</svg>",
|
|
"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
|
|
}
|