paper.js/examples/Tools/Dripping Brush.html
2011-02-11 18:50:08 +01:00

100 lines
No EOL
3 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript" src="../../src/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Item.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Point.js"></script>
<script type="text/javascript" src="../../src/Rectangle.js"></script>
<script type="text/javascript" src="../../src/Size.js"></script>
<script type="text/javascript" src="../../src/Segment.js"></script>
<script type="text/javascript" src="../../src/PathItem.js"></script>
<script type="text/javascript" src="../../src/Path.js"></script>
<script type="text/javascript" src="../../src/Doc.js"></script>
<script type="text/javascript" src="../../src/Layer.js"></script>
<script type="text/javascript" src="../../src/Group.js"></script>
<script type="text/javascript" src="../../src/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/Tool.js"></script>
<script>
window.onload = function() {
var canvas = document.getElementById('canvas');
var doc = new Doc(canvas);
var path;
var minSize = 5;
var tool = new Tool({
onMouseDown: function(event) {
},
onMouseDrag: function(event) {
// If the user dragged more then minSize:
if (event.delta.length > minSize) {
// If there is no path, make one:
if (!path) {
path = new Path();
path.fillColor = 'black';
path.add(event.lastPoint);
doc.activeLayer.appendTop(path);
}
var step = event.delta.divide(2);
step.angle = step.angle + 90;
// The top point: the middle point + the step rotated by 90 degrees:
// -----*
// |
// ------
var top = event.middlePoint.add(step);
// The bottom point: the middle point - the step rotated by 90 degrees:
// ------
// |
// -----*
var bottom = event.middlePoint.subtract(step);
path.add(top);
path.insert(0, bottom);
path.smooth();
} else {
// If the user dragged too slowly:
// If there is currently a path, close it
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;
}
}
},
onMouseUp: function(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;
}
}
});
tool.document = doc;
tool.maxDistance = 20;
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>