2011-04-23 09:47:28 -04:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
<title>Example</title>
|
2011-05-05 11:25:17 -04:00
|
|
|
<link rel="stylesheet" href="../css/style.css">
|
2011-04-23 09:47:28 -04:00
|
|
|
<script type="text/javascript">var root = '../../'</script>
|
|
|
|
<script type="text/javascript" src="../../src/load.js"></script>
|
|
|
|
<script type="text/paperscript" canvas="canvas">
|
2011-05-05 13:40:10 -04:00
|
|
|
var width, height, pathHeight, center;
|
|
|
|
|
2011-04-23 09:47:28 -04:00
|
|
|
var points = 10;
|
|
|
|
var count = 0;
|
|
|
|
var smooth = true;
|
|
|
|
var path = new Path();
|
2011-04-23 10:23:31 -04:00
|
|
|
path.fillColor = 'black';
|
2011-05-05 13:40:10 -04:00
|
|
|
initializePath();
|
|
|
|
|
|
|
|
function initializePath() {
|
|
|
|
center = document.bounds.center;
|
|
|
|
width = document.bounds.width;
|
|
|
|
height = document.bounds.height / 2;
|
|
|
|
path.segments = [];
|
|
|
|
path.add(document.bounds.bottomLeft);
|
|
|
|
for (var i = 1; i < points; i++) {
|
|
|
|
var point = new Point(width / points * i, center.y);
|
|
|
|
path.add(point);
|
|
|
|
}
|
|
|
|
path.add(document.bounds.bottomRight);
|
|
|
|
path.selected = true;
|
2011-04-23 09:47:28 -04:00
|
|
|
}
|
2011-05-05 13:40:10 -04:00
|
|
|
|
2011-04-23 09:47:28 -04:00
|
|
|
function onFrame() {
|
|
|
|
count++;
|
2011-04-23 10:23:31 -04:00
|
|
|
for (var i = 1; i < points; i++) {
|
2011-04-23 09:47:28 -04:00
|
|
|
var sinSeed = count + (i + i % 10) * 100 ;
|
|
|
|
var sinHeight = Math.sin(sinSeed / 200) * pathHeight;
|
|
|
|
var yPos = Math.sin(sinSeed / 100) * sinHeight + height;
|
|
|
|
path.segments[i].point.y = yPos;
|
|
|
|
}
|
|
|
|
if (smooth)
|
|
|
|
path.smooth();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseMove(event) {
|
|
|
|
pathHeight = center.y - event.point.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseDown(event) {
|
|
|
|
smooth = !smooth;
|
|
|
|
if (!smooth) {
|
|
|
|
// If smooth has been turned off, we need to reset
|
|
|
|
// the handles of the path:
|
2011-04-23 10:23:31 -04:00
|
|
|
for (var i = 0, l = path.segments.length; i < l; i++) {
|
2011-04-23 09:47:28 -04:00
|
|
|
var segment = path.segments[i];
|
|
|
|
segment.handleIn = segment.handleOut = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-05 13:40:10 -04:00
|
|
|
|
|
|
|
// Reposition the path whenever the window is resized:
|
2011-05-08 05:16:11 -04:00
|
|
|
DomEvent.add(window, {
|
2011-05-05 13:40:10 -04:00
|
|
|
resize: function(event) {
|
|
|
|
initializePath();
|
|
|
|
onFrame();
|
|
|
|
document.redraw();
|
|
|
|
}
|
|
|
|
});
|
2011-04-23 09:47:28 -04:00
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
2011-05-05 15:08:13 -04:00
|
|
|
<canvas id='canvas' resize></canvas>
|
2011-04-23 09:47:28 -04:00
|
|
|
</body>
|