Created
March 15, 2018 12:44
-
-
Save tkw1536/87efe4ef21ad98a33115e1bbf804bc3b to your computer and use it in GitHub Desktop.
Hack to quickly transform svg path
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
import re | |
def translatePath(pth, x, y): | |
is_x = True | |
def replacer(c): | |
nonlocal is_x | |
s = c.group() | |
print(is_x) | |
if is_x: | |
r = str(float(s) + x) | |
else: | |
r = str(float(s) + y) | |
is_x = not is_x | |
return r | |
return re.sub(r"-?\d+(\.\d+)?", replacer, pth) | |
p = translatePath("M 0.0 0.0 L -0.41998 0.0 C -1.35234 0.0 -2.09993 -0.93236 -2.09993 -1.67995 C -2.09993 -2.6123 -1.35234 -3.3599 -0.41998 -3.3599", 2.49992, 0) | |
print(p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment