mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
57 lines
No EOL
1.6 KiB
HTML
57 lines
No EOL
1.6 KiB
HTML
<!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">
|
|
<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;
|
|
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();
|
|
path.fillColor = 'black';
|
|
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;
|
|
function onFrame() {
|
|
count++;
|
|
for (var i = 1; 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, l = path.segments.length; i < l; i++) {
|
|
var segment = path.segments[i];
|
|
segment.handleIn = segment.handleOut = null;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<canvas id='canvas' resize='true'></canvas>
|
|
</body> |