Add Avalam
[xogo.git] / pieces / Avalam / generateSVG.py
1 #!/usr/bin/env python
2
3 # Compose each piece SVG with numbers
4 # https://travishorn.com/removing-parts-of-shapes-in-svg-b539a89e5649
5 # https://developer.mozilla.org/fr/docs/Web/SVG/Tutoriel/Paths
6
7 preamble = """<?xml version="1.0" encoding="UTF-8" ?>
8 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
9 <svg xmlns="http://www.w3.org/2000/svg" version="1.0" width="230" height="230">"""
10
11 black = '<circle cx="115" cy="115" r="100" fill="crimson" stroke="darkslategray"/>'
12 white = '<circle cx="115" cy="115" r="100" fill="gold" stroke="darkslategray"/>'
13
14 digits = [
15 # 1 (unused here)
16 '<path d="M130,85 v60"',
17 # 2
18 '<path d="M100,85 h30 v30 h-30 v30 h30"',
19 # 3
20 '<path d="M100,85 h30 v30 h-30 M130,115 v30 h-30"',
21 # 4
22 '<path d="M100,85 v30 h30 v30 M130,85 v30"',
23 # 5
24 '<path d="M130,85 h-30 v30 h30 v30 h-30"'
25 ]
26
27 final = "</svg>"
28
29 for color in ["white", "black"]:
30 for number in range(5):
31 filename = color + "_stack" + (str(number + 1) if number >= 1 else "") + ".svg"
32 f = open(filename, "w")
33 f.write(preamble)
34 f.write("\n")
35 f.write(white if color == "white" else black)
36 f.write("\n")
37 if number >= 1:
38 f.write(digits[number] + ' fill="none" stroke-width="5" stroke="black"/>')
39 f.write("\n")
40 f.write(final)
41 f.close()