Vector Paint Brush
Creating a threshold paint brush in Node.js
This is the thresholding logic from the mousedown event that varies the width based on the direction of the stroke.
mouseDrag: function(event) {
service.drag=true;
var delta = new service.paper.Point(event.lastPoint.x - event.point.x,
event.lastPoint.y - event.point.y);
var rad = Math.atan2(delta.y, delta.x);
var distance = service.width*3;
var top = new service.paper.Point(
event.middlePoint.x + (distance * Math.cos(service.angle*(Math.PI/180))),
event.middlePoint.y + (distance * Math.sin(service.angle*(Math.PI/180))));
var bottom = new service.paper.Point(
event.middlePoint.x + (distance * Math.cos(rad- Math.PI / 2)),
event.middlePoint.y + (distance * Math.sin(rad-Math.PI / 2)));
service.path.add(top);
service.path.insert(0, bottom);
service.path.smooth();
}
The resulting stroke emulates that of a brush.