Skip to content

Instantly share code, notes, and snippets.

@kosugi
Created October 12, 2023 09:15
Show Gist options
  • Save kosugi/292d28751a4466689f36eb6d657b2d42 to your computer and use it in GitHub Desktop.
Save kosugi/292d28751a4466689f36eb6d657b2d42 to your computer and use it in GitHub Desktop.
Last Layer の盤面を SVG で生成する. SVG の内容は Cube Voyage <https://cubevoyage.net/> から拝借しているので微妙.
# -*- coding: utf-8 -*-
import sys
usage = f'''
usage: {sys.argv[0]} ABC DEF GHI JKL MNO PQR STU
RQP
+---+
S|ABC|O
T|DEF|N
U|GHI|M
+---+
JKL
b: blue
g: green
o: orange
r: red
w: white
y: yellow
1: yellow
0: black
e.g. {sys.argv[0]} 111 111 111 ooo bbb rrr ggg
'''.strip()
template = '''
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="-0.9 -0.9 1.8 1.8">
<rect fill="#FFFFFF" x="-0.9" y="-0.9" width="1.8" height="1.8"/>
<g style="stroke-width:0.1;stroke-linejoin:round;opacity:1">
<polygon fill="#000000" stroke="#000000" points="-0.522222222222,-0.522222222222 0.522222222222,-0.522222222222 0.522222222222,0.522222222222 -0.522222222222,0.522222222222"/>
</g>
<g style="opacity:1;stroke-opacity:0.5;stroke-width:0;stroke-linejoin:round">
<polygon fill="{{U00}}" stroke="#000000" points="-0.527777777778,-0.527777777778 -0.212962962963,-0.527777777778 -0.212962962963,-0.212962962963 -0.527777777778,-0.212962962963"/>
<polygon fill="{{U01}}" stroke="#000000" points="-0.157407407407,-0.527777777778 0.157407407407,-0.527777777778 0.157407407407,-0.212962962963 -0.157407407407,-0.212962962963"/>
<polygon fill="{{U02}}" stroke="#000000" points=" 0.212962962963,-0.527777777778 0.527777777778,-0.527777777778 0.527777777778,-0.212962962963 0.212962962963,-0.212962962963"/>
<polygon fill="{{U10}}" stroke="#000000" points="-0.527777777778,-0.157407407407 -0.212962962963,-0.157407407407 -0.212962962963, 0.157407407407 -0.527777777778, 0.157407407407"/>
<polygon fill="{{U11}}" stroke="#000000" points="-0.157407407407,-0.157407407407 0.157407407407,-0.157407407407 0.157407407407, 0.157407407407 -0.157407407407, 0.157407407407"/>
<polygon fill="{{U12}}" stroke="#000000" points=" 0.212962962963,-0.157407407407 0.527777777778,-0.157407407407 0.527777777778, 0.157407407407 0.212962962963, 0.157407407407"/>
<polygon fill="{{U20}}" stroke="#000000" points="-0.527777777778, 0.212962962963 -0.212962962963, 0.212962962963 -0.212962962963, 0.527777777778 -0.527777777778, 0.527777777778"/>
<polygon fill="{{U21}}" stroke="#000000" points="-0.157407407407, 0.212962962963 0.157407407407, 0.212962962963 0.157407407407, 0.527777777778 -0.157407407407, 0.527777777778"/>
<polygon fill="{{U22}}" stroke="#000000" points=" 0.212962962963, 0.212962962963 0.527777777778, 0.212962962963 0.527777777778, 0.527777777778 0.212962962963, 0.527777777778"/>
</g>
<g style="opacity:1;stroke-opacity:1;stroke-width:0.02;stroke-linejoin:round">
<polygon fill="{{F0}}" stroke="#000000" points="-0.544061302682, 0.554406130268 -0.195913154534, 0.554406130268 -0.183908045977, 0.718390804598 -0.508045977011, 0.718390804598"/>
<polygon fill="{{F1}}" stroke="#000000" points="-0.174457215837, 0.554406130268 0.173690932312, 0.554406130268 0.161685823755, 0.718390804598 -0.162452107280, 0.718390804598"/>
<polygon fill="{{F2}}" stroke="#000000" points=" 0.195146871009, 0.554406130268 0.543295019157, 0.554406130268 0.507279693487, 0.718390804598 0.183141762452, 0.718390804598"/>
<polygon fill="{{L0}}" stroke="#000000" points="-0.554406130268,-0.544061302682 -0.554406130268,-0.195913154534 -0.718390804598,-0.183908045977 -0.718390804598,-0.508045977011"/>
<polygon fill="{{L1}}" stroke="#000000" points="-0.554406130268,-0.174457215837 -0.554406130268, 0.173690932312 -0.718390804598, 0.161685823755 -0.718390804598,-0.162452107280"/>
<polygon fill="{{L2}}" stroke="#000000" points="-0.554406130268, 0.195146871009 -0.554406130268, 0.543295019157 -0.718390804598, 0.507279693487 -0.718390804598, 0.183141762452"/>
<polygon fill="{{B0}}" stroke="#000000" points=" 0.544061302682,-0.554406130268 0.195913154534,-0.554406130268 0.183908045977,-0.718390804598 0.508045977011,-0.718390804598"/>
<polygon fill="{{B1}}" stroke="#000000" points=" 0.174457215837,-0.554406130268 -0.173690932312,-0.554406130268 -0.161685823755,-0.718390804598 0.162452107280,-0.718390804598"/>
<polygon fill="{{B2}}" stroke="#000000" points="-0.195146871009,-0.554406130268 -0.543295019157,-0.554406130268 -0.507279693487,-0.718390804598 -0.183141762452,-0.718390804598"/>
<polygon fill="{{R0}}" stroke="#000000" points=" 0.554406130268, 0.544061302682 0.554406130268, 0.195913154534 0.718390804598, 0.183908045977 0.718390804598, 0.508045977011"/>
<polygon fill="{{R1}}" stroke="#000000" points=" 0.554406130268, 0.174457215837 0.554406130268,-0.173690932312 0.718390804598,-0.161685823755 0.718390804598, 0.162452107280"/>
<polygon fill="{{R2}}" stroke="#000000" points=" 0.554406130268,-0.195146871009 0.554406130268,-0.543295019157 0.718390804598,-0.507279693487 0.718390804598,-0.183141762452"/>
</g>
</svg>
'''.strip()
placeholders = ['U0', 'U1', 'U2', 'F', 'R', 'B', 'L']
colors = {
'b': '#0000F2',
'g': '#00D800',
'o': '#FFA100',
'r': '#EE0000',
'w': '#EEEEEE',
'y': '#FEFE00',
'1': '#FEFE00',
'0': '#404040',
}
def main(content, args):
for prefix, values in zip(placeholders, args + ['000'] * 7):
for n in range(3):
key = f'{{{{{prefix}{n}}}}}'
color = colors[values[n].lower()]
content = content.replace(key, color)
return content
if __name__ == '__main__':
if 1 < len(sys.argv):
print(main(template, sys.argv[1:]))
else:
print(usage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment