Skip to content

Instantly share code, notes, and snippets.

@Holger-Will
Created July 18, 2018 06:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Holger-Will/d62d263a167b46d5319ce7658c914d73 to your computer and use it in GitHub Desktop.
Save Holger-Will/d62d263a167b46d5319ce7658c914d73 to your computer and use it in GitHub Desktop.
convert an svg path to line segments
function flatten(path,num){
var l = path.getTotalLength()
var p = path.getPointAtLength(0)
var d = `M${p.x} ${p.y}`
for(var i = (l/num);i<=l;i+=(l/num)){
p = path.getPointAtLength(i)
d+=`L${p.x} ${p.y}`
}
path.setAttribute("d",d+"z")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment