mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Some work on the Worm Farm example.
This commit is contained in:
parent
c05eb9bfde
commit
020ab4e8bb
1 changed files with 15 additions and 12 deletions
|
@ -12,13 +12,21 @@
|
||||||
|
|
||||||
var values = {
|
var values = {
|
||||||
minDistance: 10,
|
minDistance: 10,
|
||||||
|
maxDistance: 30,
|
||||||
varyThickness: true
|
varyThickness: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// All newly created items will inherit the following styles:
|
||||||
|
document.currentStyle = {
|
||||||
|
fillColor: 'white',
|
||||||
|
strokeColor: 'black'
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
// Mouse handling
|
// Mouse handling
|
||||||
|
|
||||||
tool.minDistance = values.minDistance;
|
tool.minDistance = values.minDistance;
|
||||||
|
tool.maxDistance = values.maxDistance;
|
||||||
|
|
||||||
var worm;
|
var worm;
|
||||||
|
|
||||||
|
@ -26,9 +34,8 @@
|
||||||
// and when a user drags the mouse we add points to it
|
// and when a user drags the mouse we add points to it
|
||||||
function onMouseDown(event) {
|
function onMouseDown(event) {
|
||||||
worm = new Path();
|
worm = new Path();
|
||||||
worm.fillColor = '#ffffff';
|
worm.add(event.point, event.point);
|
||||||
worm.strokeColor = '#000000';
|
worm.closed = true;
|
||||||
worm.add(event.point);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseDrag(event) {
|
function onMouseDrag(event) {
|
||||||
|
@ -62,22 +69,18 @@
|
||||||
// add the top point to the end of the path
|
// add the top point to the end of the path
|
||||||
worm.add(top);
|
worm.add(top);
|
||||||
|
|
||||||
// insert the bottom point in the beginning of the path
|
// insert the bottom point after the first segment of the path
|
||||||
worm.insert(0, bottom);
|
worm.insert(1, bottom);
|
||||||
|
|
||||||
// make a new line path from top to bottom
|
// make a new line path from top to bottom
|
||||||
var line = new Path.Line(top, bottom);
|
var line = new Path.Line(top, bottom);
|
||||||
line.strokeColor = '#000000';
|
|
||||||
|
// This is the point at the front of the worm:
|
||||||
|
worm.firstSegment.point = event.point;
|
||||||
|
|
||||||
// smooth the segments of the path
|
// smooth the segments of the path
|
||||||
worm.smooth();
|
worm.smooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMouseUp(event) {
|
|
||||||
worm.closed = true;
|
|
||||||
worm.add(event.point);
|
|
||||||
worm.smooth();
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Reference in a new issue