2011-04-19 17:32:45 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
2011-06-30 09:57:17 -04:00
|
|
|
<title>Chain</title>
|
2011-05-05 11:25:17 -04:00
|
|
|
<link rel="stylesheet" href="../css/style.css">
|
2011-06-12 14:03:18 -04:00
|
|
|
<script type="text/javascript" src="../../dist/paper.js"></script>
|
2011-04-19 17:32:45 -04:00
|
|
|
<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
|
|
|
|
2011-04-19 17:32:45 -04:00
|
|
|
var path = new Path();
|
2011-05-19 11:15:42 -04:00
|
|
|
path.style = {
|
|
|
|
strokeColor: '#E4141B',
|
|
|
|
strokeWidth: 20,
|
|
|
|
strokeCap: 'round'
|
|
|
|
};
|
|
|
|
var size = 25;
|
2011-05-15 06:36:10 -04:00
|
|
|
var segments = path.segments;
|
2011-05-19 11:15:42 -04:00
|
|
|
var start = view.center / [10, 1];
|
2011-05-03 03:54:13 -04:00
|
|
|
for (var i = 0; i < size; i++)
|
2011-05-19 11:15:42 -04:00
|
|
|
path.add(start + new Point(i * 100, 0));
|
2011-04-19 17:32:45 -04:00
|
|
|
|
2011-04-21 07:36:46 -04:00
|
|
|
function onMouseMove(event) {
|
2011-04-19 17:32:45 -04:00
|
|
|
segments[0].point = event.point;
|
2011-05-03 03:54:13 -04:00
|
|
|
for (var i = 0; i < size - 1; i++) {
|
2011-04-19 17:32:45 -04:00
|
|
|
var nextSegment = segments[i + 1];
|
|
|
|
var position = path.segments[i].point;
|
2011-04-20 18:29:46 -04:00
|
|
|
var angle = (position - nextSegment.point).angle;
|
2011-05-19 11:15:42 -04:00
|
|
|
var vector = new Point({ angle: angle, length: 35 });
|
2011-04-21 07:36:46 -04:00
|
|
|
nextSegment.point = position - vector;
|
2011-04-19 17:32:45 -04:00
|
|
|
}
|
|
|
|
path.smooth();
|
|
|
|
}
|
2011-04-21 07:36:46 -04:00
|
|
|
|
2011-04-19 17:32:45 -04:00
|
|
|
function onMouseDown(event) {
|
2011-06-20 11:16:27 -04:00
|
|
|
path.fullySelected = true;
|
2011-05-19 11:15:42 -04:00
|
|
|
path.strokeColor = '#e08285';
|
2011-04-19 17:32:45 -04:00
|
|
|
}
|
2011-05-19 11:15:42 -04:00
|
|
|
|
2011-04-19 17:32:45 -04:00
|
|
|
function onMouseUp(event) {
|
2011-06-20 11:16:27 -04:00
|
|
|
path.fullySelected = false;
|
2011-05-19 11:15:42 -04:00
|
|
|
path.strokeColor = '#e4141b';
|
2011-04-19 17:32:45 -04:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
2011-05-19 11:15:42 -04:00
|
|
|
<body>
|
2011-06-29 07:44:06 -04:00
|
|
|
<canvas id="canvas" resize></canvas>
|
2011-05-30 18:27:39 -04:00
|
|
|
</body>
|
|
|
|
</html>
|