source: main/trunk/model-sites-dev/von-sparql/js/paper/examples/Animated/Smoothing.html@ 28914

Last change on this file since 28914 was 28914, checked in by ak19, 10 years ago

Supporting javascript libraries and bespoke code written by Steffan to support the von-sparql user interface

File size: 1.7 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>Smoothing</title>
6 <link rel="stylesheet" href="../css/style.css">
7 <script type="text/javascript" src="../../dist/paper.js"></script>
8 <script type="text/paperscript" canvas="canvas">
9 var width, height, center;
10 var points = 10;
11 var smooth = true;
12 var path = new Path({
13 fillColor: 'black'
14 });
15 var mousePos = view.center / 2;
16 var pathHeight = mousePos.y;
17 initializePath();
18
19 function initializePath() {
20 center = view.center;
21 width = view.size.width;
22 height = view.size.height / 2;
23 path.segments = [];
24 path.add(view.bounds.bottomLeft);
25 for (var i = 1; i < points; i++) {
26 var point = new Point(width / points * i, center.y);
27 path.add(point);
28 }
29 path.add(view.bounds.bottomRight);
30 path.fullySelected = true;
31 }
32
33 function onFrame(event) {
34 pathHeight += (center.y - mousePos.y - pathHeight) / 10;
35 for (var i = 1; i < points; i++) {
36 var sinSeed = event.count + (i + i % 10) * 100;
37 var sinHeight = Math.sin(sinSeed / 200) * pathHeight;
38 var yPos = Math.sin(sinSeed / 100) * sinHeight + height;
39 path.segments[i].point.y = yPos;
40 }
41 if (smooth)
42 path.smooth();
43 }
44
45 function onMouseMove(event) {
46 mousePos = event.point;
47 }
48
49 function onMouseDown(event) {
50 smooth = !smooth;
51 if (!smooth) {
52 // If smooth has been turned off, we need to reset
53 // the handles of the path:
54 for (var i = 0, l = path.segments.length; i < l; i++) {
55 var segment = path.segments[i];
56 segment.handleIn = segment.handleOut = null;
57 }
58 }
59 }
60
61 // Reposition the path whenever the window is resized:
62 function onResize(event) {
63 initializePath();
64 }
65 </script>
66</head>
67<body>
68 <canvas id="canvas" resize></canvas>
69</body>
70</html>
Note: See TracBrowser for help on using the repository browser.