paper.js/examples/Tools/BezierTool.html

88 lines
No EOL
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript">var loadBase = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
document.currentStyle = {
strokeColor: '#4f7aff',
strokeWidth: 1
};
var path = new Path();
path.style = {
strokeColor: 'black',
strokeWidth: 1
};
var currentSegment;
var inLine = new Path([0, 0], [0, 0]);
var outLine = new Path([0, 0], [0, 0]);
var lastInLine = new Path([0, 0], [0, 0]);
lastInLine.visible = false;
var rect = new Path.Rectangle([0.5, 0.5], [4, 4]);
rect.fillColor = 'white';
var rectSymbol = new Symbol(rect);
var circle = new Path.Circle(0, 2);
circle.fillColor = '#4f7aff';
circle.strokeColor = null;
var circleSymbol = new Symbol(circle);
var inCircle = new PlacedSymbol(circleSymbol);
var outCircle = new PlacedSymbol(circleSymbol);
var lastInCircle = new PlacedSymbol(circleSymbol);
inCircle.position = [-100, -100];
outCircle.position = [-100, -100];
lastInCircle.position = [-100, -100];
var curRect;
function onMouseDown(event) {
if (event.count > 1) {
var first = lastInLine.firstSegment;
first.point = inLine.firstSegment.point;
var last = lastInLine.lastSegment;
last.point = inLine.lastSegment.point;
lastInLine.visible = true;
lastInCircle.position = last.point;
}
currentSegment = path.add(event.point);
inLine.firstSegment.point = event.point;
outLine.firstSegment.point = event.point;
inLine.lastSegment.point = event.point;
outLine.lastSegment.point = event.point;
inLine.visible = true;
outLine.visible = true;
outCircle.position = event.point.round() + [0.5, 0.5];
inCircle.position = event.point.round() + [0.5, 0.5];
var rect = new PlacedSymbol(rectSymbol);
rect.position = event.point.round() + [0.5, 0.5];
curRect = new Path.Rectangle([0.5, 0.5], [4, 4]);
curRect.position = event.point.round();
curRect.fillColor = '#4f7aff';
curRect.strokeWidth = 0;
}
function onMouseDrag(event) {
var delta = event.point - event.downPoint;
currentSegment.handleOut = delta;
currentSegment.handleIn = -delta;
outLine.lastSegment.point = currentSegment.handleIn + event.downPoint;
inLine.lastSegment.point = currentSegment.handleOut + event.downPoint;
outCircle.position = outLine.lastSegment.point;
inCircle.position = inLine.lastSegment.point;
}
function onMouseUp(event) {
curRect.remove();
}
</script>
</head>
<body>
Click and drag to draw a path:
<canvas id='canvas' width=1024 height=768></canvas>
</body>