mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Update Chain example.
This commit is contained in:
parent
8ab70fd0de
commit
e7475d5980
1 changed files with 17 additions and 12 deletions
|
@ -9,26 +9,31 @@
|
||||||
// Adapted from the following Processing example:
|
// Adapted from the following Processing example:
|
||||||
// http://processing.org/learning/topics/follow3.html
|
// http://processing.org/learning/topics/follow3.html
|
||||||
|
|
||||||
var path = new Path();
|
// The amount of points in the path:
|
||||||
path.style = {
|
var points = 25;
|
||||||
|
|
||||||
|
// The distance between the points:
|
||||||
|
var length = 35;
|
||||||
|
|
||||||
|
var path = new Path({
|
||||||
strokeColor: '#E4141B',
|
strokeColor: '#E4141B',
|
||||||
strokeWidth: 20,
|
strokeWidth: 20,
|
||||||
strokeCap: 'round'
|
strokeCap: 'round'
|
||||||
};
|
});
|
||||||
var size = 25;
|
|
||||||
var segments = path.segments;
|
var segments = path.segments;
|
||||||
|
|
||||||
var start = view.center / [10, 1];
|
var start = view.center / [10, 1];
|
||||||
for (var i = 0; i < size; i++)
|
for (var i = 0; i < points; i++)
|
||||||
path.add(start + new Point(i * 100, 0));
|
path.add(start + new Point(i * length, 0));
|
||||||
|
|
||||||
function onMouseMove(event) {
|
function onMouseMove(event) {
|
||||||
segments[0].point = event.point;
|
segments[0].point = event.point;
|
||||||
for (var i = 0; i < size - 1; i++) {
|
for (var i = 0; i < points - 1; i++) {
|
||||||
var nextSegment = segments[i + 1];
|
var segment = path.segments[i];
|
||||||
var position = path.segments[i].point;
|
var nextSegment = segment.next;
|
||||||
var vector = position - nextSegment.point;
|
var vector = segment.point - nextSegment.point;
|
||||||
vector.length = 35;
|
vector.length = length;
|
||||||
nextSegment.point = position - vector;
|
nextSegment.point = segment.point - vector;
|
||||||
}
|
}
|
||||||
path.smooth();
|
path.smooth();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue