Created
February 1, 2017 22:27
-
-
Save Diti/3467d243561198482401f695895e12b8 to your computer and use it in GitHub Desktop.
This file contains 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
<?xml version="1.0" encoding="utf-8" ?> | |
<svg baseProfile="tiny" height="10cm" version="1.2" viewBox="0,0,10,10" width="10cm" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink"> | |
<defs> | |
<linearGradient id="color_dark"> | |
<stop stop-color="black"/> | |
</linearGradient> | |
<linearGradient id="color_light"> | |
<stop stop-color="rgb(255,240,190)"/> | |
</linearGradient> | |
</defs> | |
<rect fill="url(#color_light)" height="10cm" width="10cm" x="0" y="0"/> | |
<g id="dark_area"> | |
<circle cx="50%" cy="50%" fill="url(#color_dark)" r="1.5"/> | |
</g> | |
<g id="circles" stroke-width="0.0125"> | |
<g id="circles_light"> | |
<circle cx="50%" cy="50%" fill="url(#color_light)" r="0.0225"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="0.25" stroke="url(#color_light)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="0.5" stroke="url(#color_light)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="0.75" stroke="url(#color_light)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="1.0" stroke="url(#color_light)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="1.25" stroke="url(#color_light)"/> | |
</g> | |
<g id="circles_dark"> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="1.5" stroke="url(#color_dark)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="1.75" stroke="url(#color_dark)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="2.0" stroke="url(#color_dark)"/> | |
<circle cx="50%" cy="50%" fill-opacity="0" r="2.25" stroke="url(#color_dark)"/> | |
</g> | |
</g> | |
</svg> |
This file contains 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/env python3 | |
'''TODO: Analyze a shooting range target and export a vector (SVG) image out of it.''' | |
import svgwrite | |
from svgwrite import cm | |
def create_target(filename, size): | |
'''Generate a SVG target and saves it to a file.''' | |
# Constants | |
color_dark = 'black' | |
mid = ('50%', '50%') | |
#radius_list = [0.25, 0.50, 0.75, 1.00, 1.25, 1.75, 2.00, 2.25] | |
# Setup `svgwrite` | |
tgt = svgwrite.Drawing(filename=filename, size=size, profile='tiny') | |
tgt.viewbox(width=10, height=10) | |
# Defs | |
color_dark = tgt.linearGradient(id='color_dark') | |
color_light = tgt.linearGradient(id='color_light') | |
color_dark.add_stop_color(color='black') | |
color_light.add_stop_color(color='rgb(255,240,190)') | |
tgt.defs.add(color_dark) | |
tgt.defs.add(color_light) | |
# Groups | |
background = tgt.rect(size=size, fill='url(#color_light)') | |
circles = tgt.g(id='circles', stroke_width='0.0125') | |
circles_dark = tgt.g(id='circles_dark') | |
circles_light = tgt.g(id='circles_light') | |
dark_area = tgt.g(id='dark_area') | |
# Output elements | |
tgt.add(background) | |
tgt.add(dark_area) | |
tgt.add(circles) | |
circles.add(circles_light) | |
circles.add(circles_dark) | |
# Dark area | |
dark_area.add(tgt.circle(center=mid, r=1.5, fill='url(#color_dark)')) | |
# Inside dark area: innermost light circle | |
circles_light.add(tgt.circle( | |
center=mid, r=0.0225, fill='url(#color_light)')) | |
# Inside dark area: all light circles | |
for cm_increments in enumerate([0.25, 0.50, 0.75, 1.00, 1.25]): | |
circles_light.add(tgt.circle(center=mid, | |
r=cm_increments[1], | |
fill_opacity=0, | |
stroke='url(#color_light)')) | |
# Outside dark area: innermost dark circle | |
circles_dark.add(tgt.circle(center=mid, | |
r=1.50, | |
fill_opacity=0, | |
stroke='url(#color_dark)')) | |
# Outside dark area: all dark circles | |
for cm_increments in enumerate([1.75, 2.00, 2.25]): | |
circles_dark.add(tgt.circle(center=mid, | |
r=cm_increments[1], | |
fill_opacity=0, | |
stroke='url(#color_dark)')) | |
tgt.save(pretty=True) | |
if __name__ == '__main__': | |
create_target('out.svg', (10 * cm, 10 * cm)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment