'use strict'; app.directive('pgLine', function () { return { restrict: 'A', replace: 'false', scope: { line: '=', list: '=' }, template: '', link: function (scope, elems, attrs) { var canvas = elems[0]; var mainTool = new paper.Tool(); mainTool.activate(); //scope.line = scope.$eval(attrs.pgLine); paper.setup(canvas); var path; var drag = false; mainTool.onMouseDown = function(event) { paper.project.clear(); // If we produced a path before, deselect it: if (path) { path.selected = false; } // Create a new path and set its stroke color to black: path = new paper.Path({ segments: [event.point], strokeColor: 'rgba(7,140,255,.3)', strokeWidth: 100, strokeCap: 'round' }); drag = true; }; mainTool.onMouseMove = function(event) { if (drag) { path.add(event.point); } } mainTool.onMouseUp = function(event) { drag = false; var segmentCount = path.segments.length; var points = Array(); // When the mouse is released, simplify it: path.simplify(10); for(var i=0; i