kaka.farm

Unnamed repository; edit this file 'description' to name the repository.
git clone https://kaka.farm/~git/kaka.farm
Log | Files | Refs | README

commit 17a31011ee0ce83a9e4ffb0f6fd762dd84dae787
parent d9771212bc4e965cb39b31ed13ff85a377e7f95e
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Tue,  2 Jun 2020 14:37:00 +0300

Update package dependencies, add border arguments to SVG generating function.

Diffstat:
A.gitignore | 2++
Mdabbling/dragon_curve.py | 36++++++++++++++++++++++++------------
Mpoetry.lock | 8++++----
3 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1,2 @@ +dabbling.egg-info +dabbling/__pycache__ diff --git a/dabbling/dragon_curve.py b/dabbling/dragon_curve.py @@ -36,24 +36,36 @@ def write_matplotlib_png(dragon_curve_path: PathType): plt.savefig('dragon-curve.png') +def transform(values, low, high): + min_value = min(values) + max_value = max(values) + old_difference = max_value - min_value + new_difference = high - low + # values = [n - min_value for n in values] # [0, max-min = old_difference] + # values = [n / old_difference for n in values] # [0, 1] + # values = [n * new_difference for n in values] # [0, new_difference = high - low] + # values = [n + low for n in values] # [low, high] + return [(n - min_value) * new_difference / old_difference + low + for n in values] + + def path_to_svg_file_content( path: PathType, - image_width = 1000, - image_height = 1000, + image_width=500, + image_height=500, + left_border=50, + right_border=50, + bottom_border=50, + top_border=50, ) -> str: - min_x = min(p[0] for p in path) - min_y = min(p[1] for p in path) - - path = [(p[0] - min_x, p[1] - min_y) for p in path] - - max_x = max(p[0] for p in path) - max_y = max(p[1] for p in path) + path = list(zip( + transform([p[0] for p in path], left_border, image_width - right_border), + transform([p[1] for p in path], top_border, image_width - bottom_border))) - path = [(image_width * p[0] / max_x, image_height * p[1] / max_y) for p in path] + svg_path = ''.join(f'L{p[0]} {p[1]}' for p in path) - svg_path = ''.join(f'L{p[0]} {p[1]}' for p in path).strip() return f''' -<svg width="{image_width}" height="{image_height}" xmlns="http://www.w3.org/2000/svg"> +<svg width="{image_width}" height="{image_height}" fill="white" xmlns="http://www.w3.org/2000/svg"> <path fill="none" stroke="black" stroke-linejoin="round" stroke-width="0.7" d="M{path[0][0]} {path[0][1]}{svg_path}"/> diff --git a/poetry.lock b/poetry.lock @@ -837,11 +837,11 @@ socks = ["PySocks (>=1.5.6,<1.5.7 || >1.5.7,<2.0)"] [[package]] category = "main" -description = "Measures number of Terminal column cells of wide-character codes" +description = "Measures the displayed width of unicode strings in a terminal" name = "wcwidth" optional = false python-versions = "*" -version = "0.1.9" +version = "0.2.2" [[package]] category = "main" @@ -1290,8 +1290,8 @@ urllib3 = [ {file = "urllib3-1.25.9.tar.gz", hash = "sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527"}, ] wcwidth = [ - {file = "wcwidth-0.1.9-py2.py3-none-any.whl", hash = "sha256:cafe2186b3c009a04067022ce1dcd79cb38d8d65ee4f4791b8888d6599d1bbe1"}, - {file = "wcwidth-0.1.9.tar.gz", hash = "sha256:ee73862862a156bf77ff92b09034fc4825dd3af9cf81bc5b360668d425f3c5f1"}, + {file = "wcwidth-0.2.2-py2.py3-none-any.whl", hash = "sha256:b651b6b081476420e4e9ae61239ac4c1b49d0c5ace42b2e81dc2ff49ed50c566"}, + {file = "wcwidth-0.2.2.tar.gz", hash = "sha256:3de2e41158cb650b91f9654cbf9a3e053cee0719c9df4ddc11e4b568669e9829"}, ] webencodings = [ {file = "webencodings-0.5.1-py2.py3-none-any.whl", hash = "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78"},