plotter_experiments/hf_sines.ipynb

105 lines
491 KiB
Plaintext
Raw Permalink Normal View History

2022-12-18 12:49:50 +01:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from lib import plot\n",
"from lib.cs_noise import noise2d\n",
"from copy import deepcopy\n",
"import IPython"
]
},
{
"cell_type": "code",
"execution_count": 2,
2022-12-18 12:49:50 +01:00
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"419.527559pt\" height=\"297.637795pt\" viewBox=\"0 0 419.527559 297.637795\" version=\"1.1\">\n<g id=\"surface1\">\n<path style=\"fill:none;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:round;stroke:rgb(0%,0%,0%);stroke-opacity:1;stroke-miterlimit:10;\" d=\"M 7.999512 7.999512 L 140.000412 7.999512 L 140.000412 97.000109 L 7.999512 97.000109 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:round;stroke:rgb(0%,30%,100%);stroke-opacity:0.5;stroke-miterlimit:10;\" d=\"M 10.000423 17.083539 L 10.062435 20.049078 L 10.124447 21.254861 L 10.187836 20.018761 L 10.249848 17.083539 L 10.31186 14.141428 L 10.37525 12.923242 L 10.437261 14.122135 L 10.500651 17.083539 L 10.562663 20.055968 L 10.624674 21.319629 L 10.688064 20.060102 L 10.750076 17.083539 L 10.812088 14.100087 L 10.875477 12.858474 L 10.937489 14.06977 L 10.999501 17.083539 L 11.062891 20.113845 L 11.124902 21.414714 L 11.186914 20.151053 L 11.250304 17.083539 L 11.312316 13.978819 L 11.374327 12.628342 L 11.437717 13.959527 L 11.499729 17.083539 L 11.563118 20.213064 L 11.62513 21.504286 L 11.687142 20.218576 L 11.750532 17.083539 L 11.812543 13.905783 L 11.874555 12.55944 L 11.937945 13.871332 L 11.999957 17.083539 L 12.061968 20.310905 L 12.125358 21.675163 L 12.18737 20.367405 L 12.249382 17.083539 L 12.312771 13.777626 L 12.374783 12.391319 L 12.438173 13.740419 L 12.500184 17.083539 L 12.562196 20.461111 L 12.625586 21.870844 L 12.687598 20.480404 L 12.749609 17.083539 L 12.812999 13.71837 L 12.875011 12.312771 L 12.937023 13.699078 L 13.000412 17.083539 L 13.062424 20.501074 L 13.124436 21.909429 L 13.187826 20.484538 L 13.249837 17.083539 L 13.311849 13.6977 L 13.375239 12.272808 L 13.43725 13.677029 L 13.50064 17.083539 L 13.562652 20.491428 L 13.624664 21.939746 L 13.688053 20.49694 L 13.750065 17.083539 L 13.812077 13.668761 L 13.875467 12.301747 L 13.937478 13.667383 L 13.99949 17.083539 L 14.06288 20.487294 L 14.124891 21.914941 L 14.186903 20.477648 L 14.250293 17.083539 L 14.312305 13.692187 L 14.374316 12.272808 L 14.437706 13.71148 L 14.499718 17.083539 L 14.563108 20.473513 L 14.625119 21.868088 L 14.687131 20.444575 L 14.750521 17.083539 L 14.812533 13.72526 L 14.874544 12.35549 L 14.937934 13.730773 L 14.999946 17.083539 L 15.061957 20.444575 L 15.125347 21.897027 L 15.187359 20.477648 L 15.249371 17.083539 L 15.31276 13.683919 L 15.374772 12.275564 L 15.438162 13.681163 L 15.500174 17.083539 L 15.562185 20.501074 L 15.625575 21.919076 L 15.687587 20.513477 L 15.749599 17.083539 L 15.812988 13.637066 L 15.875 12.199772 L 15.937012 13.615017 L 16.000401 17.083539 L 16.062413 20.582378 L 16.124425 22.036209 L 16.187815 20.615451 L 16.249826 17.083539 L 16.311838 13.518555 L 16.375228 12.002713 L 16.43724 13.496506 L 16.500629 17.083539 L 16.562641 20.640256 L 16.624653 22.127159 L 16.688043 20.616829 L 16.750054 17.083539 L 16.812066 13.537847 L 16.875456 12.089529 L 16.937467 13.56403 L 16.999479 17.083539 L 17.062869 20.558952 L 17.124881 21.989355 L 17.186892 20.543793 L 17.250282 17.083539 L 17.312294 13.645334 L 17.375684 12.224577 L 17.437695 13.652224 L 17.499707 17.083539 L 17.563097 20.495562 L 17.625109 21.910807 L 17.68712 20.468001 L 17.75051 17.083539 L 17.812522 13.712858 L 17.874533 12.312771 L 17.937923 13.703212 L 17.999935 17.083539 L 18.061947 20.477648 L 18.125336 21.894271 L 18.187348 20.455599 L 18.24936 17.083539 L 18.31275 13.700456 L 18.374761 12.318283 L 18.438151 13.734907 L 18.500163 17.083539 L 18.562174 20.410124 L 18.625564 21.777138 L 18.687576 20.425282 L 18.749588 17.083539 L 18.812977 13.773492 L 18.874989 12.383051 L 18.937001 13.794162 L 19.000391 17.083539 L 19.062402 20.359136 L 19.124414 21.6352 L 19.187804 20.269564 L 19.249816 17.083539 L 19.311827 13.912674 L 19.375217 12.595269 L 19.437229 13.927832 L 19.500618 17.083539 L 19.56263 20.20204 L 19.624642 21.480859 L 19.688032 20.1
2022-12-18 12:49:50 +01:00
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 2,
2022-12-18 12:49:50 +01:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"paper = deepcopy(plot.A6_LANDSCAPE)\n",
"\n",
"p_svg = plot.SVGPlotter('plots/hf.svg', paper)\n",
"p_hpgl = plot.HPGLPlotter(paper, 'plots/hf_{index}.hpgl')\n",
"plotter = plot.MultiPlotter()\n",
"plotter.register_plotter(p_svg)\n",
"plotter.register_plotter(p_hpgl)\n",
"\n",
"plotter.draw_frame()\n",
"\n",
"def add_lines(plotter, lines):\n",
" FREQUENCY = 2\n",
" X_OVERSAMPLING = 8\n",
" REL_AMPLITUDE = 1.4\n",
" REL_Y_MARGIN = 0.6\n",
"\n",
" line_height = paper.content_height / (lines - 1 + 2 * REL_Y_MARGIN)\n",
" x_steps = round(paper.content_width * FREQUENCY * X_OVERSAMPLING) + 1\n",
" texture = noise2d(x_steps, x_steps)\n",
" texture = texture[::(x_steps // lines), :]\n",
" texture /= np.max(np.abs(texture))\n",
"\n",
" for i in range(lines):\n",
" y = paper.top() + (i + REL_Y_MARGIN) * line_height\n",
" plotter.move_to((paper.left(), y))\n",
"\n",
" # for x in np.linspace(paper.left(), paper.right(), x_steps):\n",
" for j in range(x_steps):\n",
" x = paper.left() + j / (x_steps - 1) * paper.content_width\n",
" amplitude = line_height * REL_AMPLITUDE * texture[i, j]\n",
" plotter.line_to((x, y + amplitude / 2 * np.sin(x * FREQUENCY * 2 * np.pi)))\n",
"\n",
"paper.set_margins(10)\n",
"plotter.add_layer([0, 0.3, 1, 0.5])\n",
"add_lines(plotter, 7)\n",
"plotter.add_layer([0.6, 0.1, 0, 0.5])\n",
"add_lines(plotter, 4)\n",
"\n",
"plotter.finalise()\n",
"IPython.display.SVG(filename=p_svg.file_name)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.8 ('venv': venv)",
"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.10.8"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "d5a30a48a9b1be837de7de70323f2cebb904030d8b19bf7af129191d6d192ba3"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}