#!/usr/bin/env python3 # coding=utf-8 # SPDX-License-Identifier: GPL-2.0-or-later # Copyright (C) 2026 Alex """ Generates the icon of the extension for inkscape.org: a disc filled with the maze computed by dog_bandana_core (same function as the extension). python docs/make_icon.py # docs/icon.svg + docs/icon.png (256 px) """ import math import os import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(HERE)) from dog_bandana_core import polylines_to_d, turing_pattern # noqa: E402 SIZE = 256 INKSCAPE = [r"C:\Program Files\Inkscape\bin\inkscape.com", "/usr/bin/inkscape", "/Applications/Inkscape.app/Contents/MacOS/inkscape"] def main(): center, radius = SIZE / 2, SIZE / 2 - 8 ring = [(center + radius * math.cos(2 * math.pi * k / 180), center + radius * math.sin(2 * math.pi * k / 180)) for k in range(180)] period, width = 22, 10 lines = turing_pattern([ring], period, width, margin=6, seed=3, steps=80) svg = ('\n' '\n' '\n' '\n' '\n').format(SIZE, center, radius, polylines_to_d(lines, 2), width) svg_path = os.path.join(HERE, "icon.svg") png_path = os.path.join(HERE, "icon.png") with open(svg_path, "w", encoding="utf-8", newline="\n") as handle: handle.write(svg) print(svg_path) exe = next((path for path in INKSCAPE if os.path.exists(path)), None) if exe is None: print("Inkscape not found: export {} by hand".format(svg_path)) return subprocess.run([exe, svg_path, "--export-type=png", "--export-width={}".format(SIZE), "--export-filename={}".format(png_path)], check=True, stderr=subprocess.DEVNULL) print(png_path) if __name__ == "__main__": main()