Skip to content

Instantly share code, notes, and snippets.

@miromannino
Created October 4, 2015 13:55
Show Gist options
  • Save miromannino/e6cb896328d1b030603b to your computer and use it in GitHub Desktop.
Save miromannino/e6cb896328d1b030603b to your computer and use it in GitHub Desktop.
Use PaperJS with AngularJS (as reported in http://stackoverflow.com/a/32934066/2867909)
<!DOCTYPE html>
<html ng-app="PaperAngularExample">
<head>
<script type="text/javascript" src="bower_components/angular/angular.js"></script>
<script type="text/javascript" src="bower_components/paper/dist/paper-full.js"></script>
<script>
var app = angular.module('PaperAngularExample', []);
app.directive('draw', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var path;
paper.setup(element[0]);
var tool = new paper.Tool();
tool.onMouseDown = function(event) {
path = new paper.Path();
path.strokeColor = 'black';
};
tool.onMouseDrag = function(event) {
path.add(event.point);
};
tool.onMouseUp = function(event) {
//nothing special here
};
}
};
});
</script>
</head>
<body>
<canvas draw resize></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment