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 4ed36cd729c088842fffeea9cfdb86217b5069bb
parent bd190a5fb5973f33851009757ce1dc57e2f95cae
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Mon,  1 Jun 2020 17:26:29 +0300

Generalize and improve style of the SVG output function.

Diffstat:
Mdabbling/__init__.py | 14+++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/dabbling/__init__.py b/dabbling/__init__.py @@ -36,7 +36,11 @@ def matplotlib(dragon_curve_path: PathType): plt.savefig('dragon-curve.png') -def path_to_svg_file_content(path: PathType) -> str: +def path_to_svg_file_content( + path: PathType, + image_width = 1000, + image_height = 1000, + ) -> str: min_x = min(p[0] for p in path) min_y = min(p[1] for p in path) @@ -45,13 +49,13 @@ def path_to_svg_file_content(path: PathType) -> str: max_x = max(p[0] for p in path) max_y = max(p[1] for p in path) - path = [(200 * p[0] / max_x, 200 * p[1] / max_y) for p in path] + 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).strip() + svg_path = f'M{path[0][0]} {path[0][1]}' + ''.join(f'L{p[0]} {p[1]} ' for p in path).strip() return f''' -<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> +<svg width="{image_width}" height="{image_height}" xmlns="http://www.w3.org/2000/svg"> - <path d="M0 0 {svg_path}"/> + <path fill="none" stroke="black" stroke-linejoin="round" stroke-width="0.7" d="{svg_path}"/> </svg> '''.strip()