Last active
February 19, 2021 06:04
-
-
Save cppio/9cee96641b49796c310024da70140e2d to your computer and use it in GitHub Desktop.
Extract previews from vectormagic.com as SVG files
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
VecResult.prototype.toSVG = function() { | |
let paths = []; | |
this.pieces.forEach(piece => { | |
let index = 0; | |
piece.shapes.forEach(shape => { | |
let commands = []; | |
shape.lenghts.forEach(length => { | |
commands.push(`M ${piece.floats[index++]} ${piece.floats[index++]}`); | |
for (let i = 0; i < (length - 2) / 6; i++) { | |
commands.push(`C ${piece.floats[index++]} ${piece.floats[index++]} ${piece.floats[index++]} ${piece.floats[index++]} ${piece.floats[index++]} ${piece.floats[index++]}`); | |
} | |
commands.push("Z"); | |
}); | |
paths.push(` <path d="${commands.join(" ")}" fill="${shape.color}"/>`); | |
}); | |
}); | |
return `<svg width="${this.imageWidth}" height="${this.imageHeight}" xmlns="http://www.w3.org/2000/svg"> | |
${paths.join("\n")} | |
</svg> | |
`; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use it?