Last active
May 6, 2022 00:50
-
-
Save andiac/2d45a382ac906e32f95890bcdd6dae3c to your computer and use it in GitHub Desktop.
svg path to tikz code
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
import svgpathtools | |
from svgpathtools import svg2paths2 | |
paths, attributes, svg_attributes = svg2paths2('doubleset.svg') | |
SCALE = 10 | |
print("\\begin{tikzpicture}") | |
for path in paths: | |
print("\\begin{scope}") | |
for b in path: | |
if isinstance(b, svgpathtools.CubicBezier): | |
print(f"\\draw ({b.start.real / SCALE}, {-b.start.imag / SCALE}) .. controls ({b.control1.real / SCALE}, {-b.control1.imag / SCALE}) and ({b.control2.real / SCALE}, {-b.control2.imag / SCALE}) .. ({b.end.real / SCALE}, {-b.end.imag / SCALE});") | |
if isinstance(b, svgpathtools.Line): | |
print(f"\\draw ({b.start.real / SCALE}, {-b.start.imag / SCALE}) -- ({b.end.real / SCALE}, {-b.end.imag / SCALE});") | |
print("\\end{scope}") | |
print("\\end{tikzpicture}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment