{
"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,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": "",
"text/plain": [
""
]
},
"execution_count": 2,
"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
}