paper.js/examples/Paperjs.org/Chain.html

55 lines
1.6 KiB
HTML
Raw Permalink Normal View History

2011-04-19 17:32:45 -04:00
<!DOCTYPE html>
<html>
<head>
2014-08-16 13:24:54 -04:00
<meta charset="UTF-8">
<title>Chain</title>
<link rel="stylesheet" href="../css/style.css">
<script type="text/javascript" src="../../dist/paper-full.js"></script>
<script type="text/paperscript" canvas="canvas">
// Adapted from the following Processing example:
// http://processing.org/learning/topics/follow3.html
2011-05-19 11:15:42 -04:00
2014-08-16 13:24:54 -04:00
// The amount of points in the path:
var points = 25;
2013-03-02 12:35:10 -05:00
2014-08-16 13:24:54 -04:00
// The distance between the points:
var length = 35;
2013-03-02 12:35:10 -05:00
2014-08-16 13:24:54 -04:00
var path = new Path({
strokeColor: '#E4141B',
strokeWidth: 20,
strokeCap: 'round'
});
2013-03-02 12:35:10 -05:00
2014-08-16 13:24:54 -04:00
var start = view.center / [10, 1];
for (var i = 0; i < points; i++)
path.add(start + new Point(i * length, 0));
2011-04-19 17:32:45 -04:00
2014-08-16 13:24:54 -04:00
function onMouseMove(event) {
path.firstSegment.point = event.point;
for (var i = 0; i < points - 1; i++) {
var segment = path.segments[i];
var nextSegment = segment.next;
var vector = segment.point - nextSegment.point;
vector.length = length;
nextSegment.point = segment.point - vector;
}
path.smooth({ type: 'continuous' });
2014-08-16 13:24:54 -04:00
}
2011-04-21 07:36:46 -04:00
2014-08-16 13:24:54 -04:00
function onMouseDown(event) {
path.fullySelected = true;
path.strokeColor = '#e08285';
}
2011-05-19 11:15:42 -04:00
2014-08-16 13:24:54 -04:00
function onMouseUp(event) {
path.fullySelected = false;
path.strokeColor = '#e4141b';
}
</script>
2011-04-19 17:32:45 -04:00
</head>
2011-05-19 11:15:42 -04:00
<body>
2014-08-16 13:24:54 -04:00
<canvas id="canvas" resize></canvas>
2011-05-30 18:27:39 -04:00
</body>
</html>