Skip to content

Commit

Permalink
simpler worker
Browse files Browse the repository at this point in the history
  • Loading branch information
forresto committed Oct 25, 2014
1 parent 14f0f7e commit 92e7b6f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions turtle-svg-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Worker setup
self.onmessage = function(e) {
importScripts('./turtle-parse.js');
_resetTurtle();

try {
eval(e.data);

// Build SVG string
var svg = '<svg id="turtle-svg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="'+
Math.ceil(_max.x) + '" height="' +
Math.ceil(_max.y) +'">'+"\n";
for (var i=0; i<_paths.length; i++) {
var path = _paths[i];
svg += ' <path id="turtle-path-'+ i +'" '+
'stroke="' + path.color + '" '+
'd="' + path.d + '" '+
'fill="' + (path.fill ? path.fill : 'none') + '" vector-effect="non-scaling-stroke" />' + "\n";
}
svg += '</svg>';

self.postMessage({
svg: svg,
code: e.data,
paths: _paths
});

// Terminate self
self.close();
} catch (error) {
// err
self.postMessage("");
}
};

0 comments on commit 92e7b6f

Please sign in to comment.