paper.js/examples/Tools/Dripping Brush.html
2011-02-16 22:35:17 +01:00

95 lines
No EOL
3.1 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="../../lib/Bootstrap.js"></script>
<script type="text/javascript" src="../../src/Paper.js"></script>
<script type="text/javascript" src="../../src/tool/ToolEvent.js"></script>
<script type="text/javascript" src="../../src/tool/ToolHandler.js"></script>
<script type="text/javascript" src="../../src/tool/Tool.js"></script>
<script type="text/javascript" src="../../src/basic/Point.js"></script>
<script type="text/javascript" src="../../src/basic/Rectangle.js"></script>
<script type="text/javascript" src="../../src/basic/Size.js"></script>
<script type="text/javascript" src="../../src/basic/Matrix.js"></script>
<script type="text/javascript" src="../../src/document/Doc.js"></script>
<script type="text/javascript" src="../../src/item/Item.js"></script>
<script type="text/javascript" src="../../src/item/Group.js"></script>
<script type="text/javascript" src="../../src/item/Layer.js"></script>
<script type="text/javascript" src="../../src/item/PathStyle.js"></script>
<script type="text/javascript" src="../../src/path/Segment.js"></script>
<script type="text/javascript" src="../../src/path/PathItem.js"></script>
<script type="text/javascript" src="../../src/path/Path.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({
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);
}
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.maxDistance = 20;
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>