Skip to content

Instantly share code, notes, and snippets.

@tkw1536
Created March 15, 2018 12:44
Show Gist options
  • Save tkw1536/87efe4ef21ad98a33115e1bbf804bc3b to your computer and use it in GitHub Desktop.
Save tkw1536/87efe4ef21ad98a33115e1bbf804bc3b to your computer and use it in GitHub Desktop.
Hack to quickly transform svg path
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