qrohlf / trianglify

Algorithmically generated triangle art
http://qrohlf.com/trianglify/
GNU General Public License v3.0
10.08k stars 669 forks source link

Export to SVG #73

Closed pwichmann closed 7 years ago

pwichmann commented 7 years ago

First of all: This looks like an amazing library! Thank you.

How would I export the result into SVG (so that I could import it into paper.js)? Currently, if I try to run (on node.js):

// Trianglify
var pattern = trianglify({
        width: 300,
        height: 200
 });
var pattern_as_svg = pattern.svg({includeNamespace: true});

// Paper.js - Import SVG from string
var icon_item = paper.project.importSVG(pattern_as_svg); // end import SVG

I run into errors:

Error: TypeError: First argument to Node.prototype.insertBefore must be a Node

qrohlf commented 7 years ago

pattern.svg() returns a dom node object, not a string.

In the case of Node, it returns a jsdom object.

Anyways, just replace the line:

var pattern_as_svg = pattern.svg({includeNamespace: true}).outerHTML;

and you should be good to go

pwichmann commented 7 years ago

You are my hero of the day. Thank you!