paper.js/examples/Node.js/SVGExport.js

50 lines
947 B
JavaScript
Raw Normal View History

2013-05-08 23:19:49 -04:00
var paper = require('paper'),
path = require('path'),
fs = require('fs');
paper.setup(new paper.Canvas(300, 600));
with (paper) {
var stops = [new Color(1, 1, 0, 0), 'red', 'black'];
var radius = view.bounds.width * 0.4,
from = new Point(view.center.x),
to = from.add(radius, 0);
2013-05-08 23:19:49 -04:00
var circle = new Path.Circle({
2013-05-08 23:19:49 -04:00
center: from,
radius: radius,
fillColor: {
stops: stops,
radial: true,
origin: from,
destination: to
},
strokeColor: 'black'
});
2013-05-08 23:19:49 -04:00
var from = view.bounds.leftCenter,
to = view.bounds.bottomRight;
var rect = new Path.Rectangle({
from: from,
to: to,
fillColor: {
stops: stops,
radial: false,
origin: from,
destination: to
},
strokeColor: 'black'
});
rect.rotate(45).scale(0.7);
2013-11-26 11:33:03 -05:00
var svg = project.exportSVG({ asString: true });
2013-05-08 23:19:49 -04:00
console.log(svg);
fs.writeFile(path.resolve(__dirname, 'out.svg'),svg, function (err) {
if (err) throw err;
2013-10-10 17:12:53 -04:00
console.log('Saved!');
2013-05-08 23:19:49 -04:00
});
2013-10-10 17:12:53 -04:00
}