From e2ae03d571c41edd022079a003d8ce008fb6ea03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 8 May 2013 20:19:49 -0700 Subject: [PATCH] Update exportSVG example. --- examples/Node.js/exportSVG.js | 59 ++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/examples/Node.js/exportSVG.js b/examples/Node.js/exportSVG.js index 1ad9612e..9690c247 100644 --- a/examples/Node.js/exportSVG.js +++ b/examples/Node.js/exportSVG.js @@ -1,13 +1,50 @@ -var paper = require('paper'); -paper.setup(new paper.Canvas(1024, 768)); -var scope = {}; -paper.install(scope); -with (scope) { +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 + [radius, 0]; + var circle = new Path.Circle({ - center: [100, 100], - radius: 50, - fillColor: 'red' + center: from, + radius: radius, + fillColor: { + stops: stops, + radial: true, + origin: from, + destination: to + }, + strokeColor: 'black' }); - var svg = project.exportSVG(); - console.log(svg.outerHTML); -}; \ No newline at end of file + + 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); + + var svg = new XMLSerializer().serializeToString(project.exportSVG()); + + console.log(svg); + + fs.writeFile(path.resolve(__dirname, 'out.svg'),svg, function (err) { + if (err) throw err; + console.log('Saved!'); + }); +} \ No newline at end of file