{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from lib import plot\n", "import IPython\n", "from random import randint, randrange\n", "\n", "paper = plot.A6_PORTRAIT" ] }, { "cell_type": "code", "execution_count": 2, "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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\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\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p_svg = plot.SVGPlotter('plots/choices.svg', paper)\n", "p_hpgl = plot.HPGLPlotter(paper, 'plots/choices_{index}.hpgl')\n", "plotter = plot.MultiPlotter()\n", "plotter.register_plotter(p_svg)\n", "plotter.register_plotter(p_hpgl)\n", "\n", "plotter.move_to(paper.bottom_left())\n", "plotter.line_to(paper.bottom_right())\n", "plotter.line_to(paper.top_right())\n", "plotter.line_to(paper.top_left())\n", "plotter.line_to(paper.bottom_left())\n", "\n", "plotter.add_layer([0.3, 0.15, 0, 0.5])\n", "\n", "def face(head=0, mouth=0, eyes=0):\n", " yield None\n", " if head == 0:\n", " yield (-1, -1)\n", " yield (-1, 1)\n", " yield (1, 1)\n", " yield (1, -1)\n", " yield (-1, -1)\n", " elif head == 1:\n", " for i in np.linspace(0, 2 * np.pi, 7):\n", " yield(1.2 * np.cos(i), 1.2 * np.sin(i))\n", " elif head == 2:\n", " for i in np.linspace(0, 2 * np.pi, 7):\n", " yield(1.2 * np.sin(i), 1.2 * np.cos(i))\n", " elif head == 3:\n", " for i in np.linspace(0, 2 * np.pi, 17):\n", " yield(1.1 * np.cos(i), 1.1 * np.sin(i))\n", " elif head == 4:\n", " yield (-1.3, 1.1)\n", " yield (1.3, 1.1)\n", " yield (0, -1.3)\n", " yield (-1.3, 1.1)\n", " elif head == 5:\n", " yield (-1.2, -1.0)\n", " yield (1.2, -1.0)\n", " yield (0.5, 1.1)\n", " yield (-0.5, 1.1)\n", " yield (-1.2, -1.0)\n", "\n", " yield None\n", " if mouth == 0:\n", " yield (-0.3, 0.6)\n", " yield (0.3, 0.6)\n", " elif mouth == 1:\n", " yield (-0.45, 0.4)\n", " yield (0.45, 0.6)\n", " elif mouth == 2:\n", " for i in np.linspace(-0.3 * np.pi, 0.3 * np.pi, 17):\n", " yield(0.4 * np.sin(i), 0.4 * np.cos(i) + 0.2)\n", " elif mouth == 3:\n", " for i in np.linspace(-0.3 * np.pi, 0.3 * np.pi, 17):\n", " yield(0.4 * np.sin(i), -0.4 * np.cos(i) + 0.8)\n", "\n", " if eyes == 0:\n", " yield None\n", " yield (-0.4, -0.2)\n", " yield (-0.2, -0.2)\n", " yield None\n", " yield (0.4, -0.2)\n", " yield (0.2, -0.2)\n", " elif eyes == 1:\n", " yield None\n", " yield (-0.4, -0.3)\n", " yield (-0.2, -0.1)\n", " yield None\n", " yield (-0.4, -0.1)\n", " yield (-0.2, -0.3)\n", " yield None\n", " yield (0.4, -0.3)\n", " yield (0.2, -0.1)\n", " yield None\n", " yield (0.4, -0.1)\n", " yield (0.2, -0.3)\n", " elif eyes == 2:\n", " yield None\n", " for i in np.linspace(0, 2 * np.pi, 9):\n", " yield(0.25 * np.cos(i) - 0.3, 0.25 * np.sin(i) - 0.2)\n", " yield None\n", " for i in np.linspace(0, 2 * np.pi, 9):\n", " yield(0.25 * np.cos(i) + 0.3, 0.25 * np.sin(i) - 0.2)\n", " yield None\n", " yield (0.7, -0.2)\n", " yield (0.55, -0.2)\n", " yield None\n", " yield (-0.55, -0.2)\n", " yield (-0.7, -0.2)\n", " elif eyes == 3:\n", " yield None\n", " for i in np.linspace(0, 2 * np.pi, 9):\n", " yield(0.1 * np.cos(i) - 0.2, 0.1 * np.sin(i) - 0.2)\n", " yield None\n", " for i in np.linspace(0, 2 * np.pi, 9):\n", " yield(0.1 * np.cos(i) + 0.2, 0.1 * np.sin(i) - 0.2)\n", " elif eyes == 4:\n", " yield None\n", " for i in np.linspace(0, 2 * np.pi, 9):\n", " yield(0.1 * np.cos(i) - 0.3, 0.1 * np.sin(i) - 0.2)\n", " yield None\n", " for i in np.linspace(-0.3 * np.pi, 0.3 * np.pi, 17):\n", " yield(0.2 * np.sin(i) + 0.3, 0.1 * np.cos(i) - 0.25)\n", " elif eyes == 5:\n", " yield None\n", " for i in np.linspace(-0.3 * np.pi, 0.3 * np.pi, 17):\n", " yield(0.2 * np.sin(i) - 0.3, -0.2 * np.cos(i) - 0.2)\n", " yield None\n", " for i in np.linspace(-0.3 * np.pi, 0.3 * np.pi, 17):\n", " yield(0.2 * np.sin(i) + 0.3, -0.2 * np.cos(i) - 0.2)\n", "\n", "size = 5\n", "dist = 3\n", "count_h = (paper.content_width - dist) // (size + dist)\n", "count_v = (paper.content_height - dist) // (size + dist)\n", "dist_h = (paper.content_width - dist) / count_h\n", "dist_v = (paper.content_height - dist) / count_v\n", "\n", "for xi in range(count_h):\n", " x = paper.centre()[0] + (xi - (count_h - 1) / 2) * dist_h\n", " for yi in range(count_v):\n", " y = paper.centre()[1] + (yi - (count_v - 1) / 2) * dist_v\n", "\n", " up = False\n", "\n", " head = randrange(6)\n", " mouth = randrange(4)\n", " eyes = randrange(6)\n", " scale = 1 + (0.5 - np.random.rand()) * 0.4\n", " for p in face(head, mouth, eyes):\n", " if p is None:\n", " up = True\n", " continue\n", " p = np.array(p) * size * scale / 2 + [x, y]\n", " if up:\n", " plotter.move_to(p)\n", " up = False\n", " else:\n", " plotter.line_to(p)\n", "\n", "plotter.finalise()\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 }