paper.js/examples/Animated/Smoothing.html
2011-04-23 15:47:28 +02:00

54 lines
No EOL
1.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Example</title>
<script type="text/javascript">var root = '../../'</script>
<script type="text/javascript" src="../../src/load.js"></script>
<script type="text/paperscript" canvas="canvas">
var width = document.bounds.width - 10;
var height = document.bounds.height / 2;
var pathHeight = document.bounds.height / 2;
var points = 10;
var count = 0;
var smooth = true;
var center = document.bounds.center;
var path = new Path();
for (var i = 0; i < points; i++) {
var point = new Point(width / points * i + 5, center.y);
path.add(point);
}
path.selected = true;
function onFrame() {
count++;
for (var i = 0; i < points; i++) {
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:
for (var i = 0; i < points; i++) {
var segment = path.segments[i];
segment.handleIn = segment.handleOut = null;
}
}
}
</script>
</head>
<body>
<canvas id='canvas' width=1024 height=768></canvas>
</body>