Skip to content

Instantly share code, notes, and snippets.

@frozonfreak
Last active February 17, 2016 01:20
Show Gist options
  • Save frozonfreak/8016752 to your computer and use it in GitHub Desktop.
Save frozonfreak/8016752 to your computer and use it in GitHub Desktop.
PaperJS with AngularJS
<!DOCTYPE html>
<html ng-app>
<head>
<meta charset="UTF-8">
<title>Lines</title>
<script type="text/javascript" src="js/vendor/paper.js"></script>
<script type="text/javascript" src="js/vendor/angular.min.js"></script>
</head>
<body ng-controller="PaperController">
<canvas id="canvas" resize ng-mousedown="mouseDown($event)" ng-mousemove="mouseDrag($event)" ng-mouseup="mouseUp()"></canvas>
</body>
<script type="text/javascript">
function PaperController($scope){
var path;
var drag = false;
$scope.mouseUp = function(){
//Clear Mouse Drag Flag
drag = false;
};
$scope.mouseDrag = function(event){
if(drag){
path.add(new paper.Point(event.x, event.y));
path.smooth();
}
};
$scope.mouseDown = function(event){
//Set flag to detect mouse drag
drag = true;
path = new paper.Path();
path.strokeColor = 'black';
path.add(new paper.Point(event.x, event.y));
};
init();
function init(){
paper.install(window);
paper.setup('canvas');
}
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment