mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
113 lines
No EOL
4.3 KiB
HTML
113 lines
No EOL
4.3 KiB
HTML
<!DOCTYPE html>
|
|
<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="../../lib/parse-js.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/DocumentView.js"></script>
|
|
<script type="text/javascript" src="../../src/document/Document.js"></script>
|
|
<script type="text/javascript" src="../../src/document/Symbol.js"></script>
|
|
<script type="text/javascript" src="../../src/item/Item.js"></script>
|
|
<script type="text/javascript" src="../../src/item/PlacedSymbol.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/Raster.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 type="text/javascript" src="../../src/path/CompoundPath.js"></script>
|
|
<script type="text/javascript" src="../../src/path/Path.Constructors.js"></script>
|
|
<script type="text/javascript" src="../../src/color/Color.js"></script>
|
|
<script type="text/javascript" src="../../src/color/RGBColor.js"></script>
|
|
<script type="text/javascript" src="../../src/color/GrayColor.js"></script>
|
|
<script type="text/javascript" src="../../src/color/GradientColor.js"></script>
|
|
<script type="text/javascript" src="../../src/color/Gradient.js"></script>
|
|
<script type="text/javascript" src="../../src/color/GradientStop.js"></script>
|
|
<script type="text/javascript" src="../../src/util/PaperScript.js"></script>
|
|
<script type="text/paperscript" canvas="canvas">
|
|
/////////////////////////////////////////////////////////////////////
|
|
// Values
|
|
|
|
var values = {
|
|
minDistance: 10,
|
|
varyThickness: true
|
|
};
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
// Mouse handling
|
|
|
|
tool.minDistance = values.minDistance;
|
|
|
|
var worm;
|
|
|
|
// Every time the user clicks the mouse to drag we create a path
|
|
// and when a user drags the mouse we add points to it
|
|
function onMouseDown(event) {
|
|
worm = new Path();
|
|
worm.fillColor = '#ffffff';
|
|
worm.strokeColor = '#000000';
|
|
worm.add(event.point);
|
|
}
|
|
|
|
function onMouseDrag(event) {
|
|
// the vector in the direction that the mouse moved
|
|
var step = event.delta;
|
|
|
|
// if the vary thickness checkbox is marked
|
|
// divide the length of the step vector by two:
|
|
if (values.varyThickness) {
|
|
step.length = step.length / 2;
|
|
} else {
|
|
// otherwise set the length of the step vector to half of
|
|
// minDistance
|
|
step.length = values.minDistance / 2;
|
|
}
|
|
|
|
// the top point: the middle point + the step rotated by -90
|
|
// degrees
|
|
// -----*
|
|
// |
|
|
// ------
|
|
var top = event.middlePoint + step.rotate(-90);
|
|
|
|
// the bottom point: the middle point + the step rotated by 90
|
|
// degrees
|
|
// ------
|
|
// |
|
|
// -----*
|
|
var bottom = event.middlePoint + step.rotate(90);
|
|
|
|
// add the top point to the end of the path
|
|
worm.add(top);
|
|
|
|
// insert the bottom point in the beginning of the path
|
|
worm.insert(0, bottom);
|
|
|
|
// make a new line path from top to bottom
|
|
var line = new Path.Line(top, bottom);
|
|
line.strokeColor = '#000000';
|
|
|
|
// smooth the segments of the path
|
|
worm.smooth();
|
|
}
|
|
|
|
function onMouseUp(event) {
|
|
worm.closed = true;
|
|
worm.add(event.point);
|
|
worm.smooth();
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<canvas id='canvas' width=1024 height=768></canvas>
|
|
</body> |