Created
July 4, 2014 10:36
-
-
Save Zverik/cf3c7a55c89430c930c0 to your computer and use it in GitHub Desktop.
Generate SVG shields for osm.org style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Generate SVG shields for https://github.com/gravitystorm/openstreetmap-carto | |
WIDTHS = { | |
1: 0.0, 2: 7.25, 3: 14.5, 4: 21.0, | |
5: 28.5, 6: 34.5, 7: 41.25, 8: 48.0, | |
9: 52.5, 10: 57.75, 11: 62.75 | |
} | |
TYPES = { 'mot': '#7788a1', 'pri': '#bb7b7f', 'sec': '#c6ad84', 'ter': '#c4c68f' } | |
for t in TYPES: | |
for w in WIDTHS: | |
width = WIDTHS[w] | |
with open('{}_shield{}.svg'.format(t, w), 'w') as svg: | |
svg.write('<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 {} 19.5">\n'.format(19.25 + width)) | |
for r in [9, 7.5, 6]: | |
color = 'white' if r == 7.5 else TYPES[t] | |
if width <= 0: | |
svg.write('<circle fill="{}" cx="10.25" cy="10.75" r="{}"/>\n'.format(color, r)) | |
else: | |
svg.write('<g fill="{}">\n'.format(color)) | |
svg.write('<circle cx="10.25" cy="10.75" r="{}"/>\n'.format(r)) | |
svg.write('<rect x="10.25" y="{}" width="{}" height="{}"/>\n'.format(10.75 - r, width, r * 2)) | |
svg.write('<circle cx="{}" cy="10.75" r="{}"/>\n'.format(10.25 + width, r)) | |
svg.write('</g>\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment