From 9883853b68b4989f623d03a8222c9affba0c671f Mon Sep 17 00:00:00 2001 From: fruchti Date: Sun, 11 Dec 2022 15:37:03 +0100 Subject: [PATCH] Add globe plot experiment --- globe.ipynb | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 globe.ipynb diff --git a/globe.ipynb b/globe.ipynb new file mode 100644 index 0000000..67c17aa --- /dev/null +++ b/globe.ipynb @@ -0,0 +1,111 @@ +{ + "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": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", + "text/plain": [ + "" + ] + }, + "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 +}