Skip to content

Commit e2ae03d

Browse files
committed
Update exportSVG example.
1 parent 731a873 commit e2ae03d

1 file changed

Lines changed: 48 additions & 11 deletions

File tree

examples/Node.js/exportSVG.js

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
1-
var paper = require('paper');
2-
paper.setup(new paper.Canvas(1024, 768));
3-
var scope = {};
4-
paper.install(scope);
5-
with (scope) {
1+
var paper = require('paper'),
2+
path = require('path'),
3+
fs = require('fs');
4+
5+
paper.setup(new paper.Canvas(300, 600));
6+
with (paper) {
7+
var stops = [new Color(1, 1, 0, 0), 'red', 'black'];
8+
9+
var radius = view.bounds.width * 0.4,
10+
from = new Point(view.center.x),
11+
to = from + [radius, 0];
12+
613
var circle = new Path.Circle({
7-
center: [100, 100],
8-
radius: 50,
9-
fillColor: 'red'
14+
center: from,
15+
radius: radius,
16+
fillColor: {
17+
stops: stops,
18+
radial: true,
19+
origin: from,
20+
destination: to
21+
},
22+
strokeColor: 'black'
1023
});
11-
var svg = project.exportSVG();
12-
console.log(svg.outerHTML);
13-
};
24+
25+
var from = view.bounds.leftCenter,
26+
to = view.bounds.bottomRight;
27+
28+
var rect = new Path.Rectangle({
29+
from: from,
30+
to: to,
31+
fillColor: {
32+
stops: stops,
33+
radial: false,
34+
origin: from,
35+
destination: to
36+
},
37+
strokeColor: 'black'
38+
});
39+
40+
rect.rotate(45).scale(0.7);
41+
42+
var svg = new XMLSerializer().serializeToString(project.exportSVG());
43+
44+
console.log(svg);
45+
46+
fs.writeFile(path.resolve(__dirname, 'out.svg'),svg, function (err) {
47+
if (err) throw err;
48+
console.log('Saved!');
49+
});
50+
}

0 commit comments

Comments
 (0)