paper.js/examples/Tools/DrippingBrush.html

74 lines
1.7 KiB
HTML
Raw Normal View History

2011-02-21 14:31:26 +01:00
<!DOCTYPE html>
2011-02-09 01:10:55 +01:00
<html>
<head>
2013-06-02 13:41:10 -07:00
<meta charset="UTF-8">
<title>Dripping Brush</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper-full.js"></script>
2011-03-04 12:38:38 +01:00
<script type="text/paperscript" canvas="canvas">
var path;
var minSize = 5;
tool.maxDistance = 20;
function onMouseDrag(event) {
// If the user dragged more then minSize:
if (event.delta.length > minSize) {
// If there is no path, make one:
if (!path) {
2013-03-09 16:02:11 +01:00
path = new Path({
fillColor: 'black'
});
2011-03-04 12:38:38 +01:00
path.add(event.lastPoint);
}
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
var step = event.delta / 2;
step.angle = step.angle + 90;
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
// The top point: the middle point + the step rotated by 90 degrees:
// -----*
// |
// ------
var top = event.middlePoint + step;
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
// The bottom point: the middle point - the step rotated by 90 degrees:
// ------
// |
// -----*
var bottom = event.middlePoint - step;
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
path.add(top);
path.insert(0, bottom);
path.smooth();
} else {
// If the user dragged too slowly:
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
// If there is currently a path, close it
if (path) {
path.add(event.point);
path.closed = true;
path.smooth();
2011-02-09 01:10:55 +01:00
2011-03-04 12:38:38 +01:00
// Set path to null (nothing) so the path check above
// will force a new path next time the user drags fast enough:
path = null;
2011-02-09 01:10:55 +01:00
}
2011-03-04 12:38:38 +01:00
}
}
2011-07-07 16:09:02 +02:00
2011-03-04 12:38:38 +01:00
function onMouseUp(event) {
if (path) {
path.add(event.point);
path.closed = true;
path.smooth();
// Set path to null (nothing) so the path check above
// will force a new path next time the user drags fast enough:
path = null;
}
2011-02-09 01:10:55 +01:00
}
</script>
</head>
<body>
<canvas id="canvas" resize></canvas>
2011-05-31 00:27:39 +02:00
</body>
</html>