class Glyph:
# ...
def svg(self, **kwargs):
unit = kwargs.get('unit') or SVG_OPTIONS['unit']
outer_color = kwargs.get('outer_color') or SVG_OPTIONS['outer_color']
inner_color = kwargs.get('inner_color') or SVG_OPTIONS['inner_color']
outer_thick = kwargs.get('outer_thick') or SVG_OPTIONS['outer_thick']
inner_thick = kwargs.get('inner_thick') or SVG_OPTIONS['inner_thick']
path_color = kwargs.get('path_color') or SVG_OPTIONS['path_color']
path_thick = kwargs.get('path_thick') or SVG_OPTIONS['path_thick']
half = unit//2
outer_lines = 'M 0 0 L '
inner_lines = 'M {} {} L '.format(unit, unit)
path = 'M {} {} '.format(half, half)
path += 'L {} {} '.format(unit+half, half)
square = self.squares[Vector(1,0)]
while square.pos != Vector(0,0):
x = square.pos.x * unit
y = square.pos.y * unit
path += '{} {} '.format(x+half, y+half)
move = MOVES[square._in + square._out]
# inner walls:
if move != 'r':
start_x = x + (0 if square._out in 'rd' else unit)
start_y = y + (0 if square._out in 'ld' else unit)
end_x = start_x + (0 if square._out in 'ud' else (unit if square._out=='r' else -unit))
end_y = start_y + (0 if square._out in 'lr' else (unit if square._out=='d' else -unit))
if move == 'L':
inner_lines += '{} {} '.format(start_x, start_y)
inner_lines += '{} {} '.format(end_x, end_y)
# outer walls:
if move != 'L':
start_x = x + (0 if square._out in 'ru' else unit)
start_y = y + (0 if square._out in 'rd'else unit)
end_x = start_x + (0 if square._out in 'ud' else (unit if square._out=='r' else -unit))
end_y = start_y + (0 if square._out in 'lr' else (unit if square._out=='d' else -unit))
if move == 'r':
outer_lines += '{} {} '.format(start_x, start_y)
outer_lines += '{} {} '.format(end_x, end_y)
square = square.next()
path += 'Z'
outer_lines += 'Z'
inner_lines += 'Z'
svg = '''
<svg id="svg" version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" width="{}" height="{}">
<defs>
<linearGradient id="linear1" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#05a"/>
<stop offset="100%" stop-color="#0a5"/>
</linearGradient>
</defs>
<style>
#outer {{
stroke: {};
stroke-width: {};
fill: transparent;
}}
#inner {{
stroke: {};
stroke-width: {};
fill: transparent;
}}
#path {{
stroke: {};
stroke-width: {};
fill: transparent;
}}
</style>
<g id="glyph" transform="translate({},{})">
<path id="path" d="{}" />
<path id="outer" d="{}" />
<path id="inner" d="{}" />
</g>
</svg>'''.format((self.size.x+1)*unit, (self.size.y+1)*unit, outer_color, outer_thick, inner_color, inner_thick, path_color, path_thick, unit/2, unit/2, path, outer_lines, inner_lines)
return svg