Files
inkscape.motif.DogBandana/docs/make_icon.py
T
AlexandClaude Opus 5.5 2353640d2a Rename Docs/ to docs/ so README image links resolve
The README references docs/apercu.png and docs/parametres.png, but the
folder was tracked as Docs/, which breaks the links on case-sensitive
hosts such as the Gitea server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 18:56:52 +01:00

58 lines
2.1 KiB
Python

#!/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 = ('<?xml version="1.0" encoding="UTF-8"?>\n'
'<svg xmlns="http://www.w3.org/2000/svg" width="{0}" height="{0}" '
'viewBox="0 0 {0} {0}">\n'
'<circle cx="{1}" cy="{1}" r="{2}" fill="#ffffff" stroke="#212529" '
'stroke-width="6"/>\n'
'<path d="{3}" fill="none" stroke="#212529" stroke-width="{4}" '
'stroke-linecap="round" stroke-linejoin="round"/>\n'
'</svg>\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()