paper.js/examples/Scripts/Chain.html

46 lines
1.3 KiB
HTML
Raw Normal View History

2011-04-19 17:32:45 -04:00
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<link rel="stylesheet" href="../css/style.css">
2011-04-19 17:32:45 -04:00
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
// Adapted from the following Processing example:
// http://processing.org/learning/topics/follow3.html
var path = new Path();
path.strokeColor = 'purple';
path.strokeWidth = 20;
path.strokeCap = 'round';
var size = 20;
var segments = path.segments;
var center = view.center;
2011-05-03 03:54:13 -04:00
for (var i = 0; i < size; i++)
2011-04-19 17:32:45 -04:00
path.add(center + new Point(i * 100, 0));
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;
var angle = (position - nextSegment.point).angle;
2011-04-21 07:36:46 -04:00
var vector = new Point({ angle: angle, length: 25 });
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) {
path.selected = true;
}
function onMouseUp(event) {
path.selected = false;
}
</script>
</head>
<body style='background-color: black'>
<canvas id="canvas" resize keepalive="true"></canvas>
2011-04-19 17:32:45 -04:00
</body>