source: main/trunk/model-sites-dev/von-sparql/js/paper/examples/Tools/SquareRounded.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.9 KB
Line 
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="UTF-8">
5 <title>Square Rounded</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 /////////////////////////////////////////////////////////////////////
10 // Values
11
12 var values = {
13 radius: 10,
14 tolerance: 5
15 };
16
17 checkValues();
18
19 /////////////////////////////////////////////////////////////////////
20 // Mouse handling
21
22 var handle;
23 function checkValues() {
24 var min = values.radius * 2;
25 if (values.tolerance < min) values.tolerance = min;
26 handle = values.radius * Numerical.KAPPA;
27 }
28
29 var path;
30 function onMouseDown(event) {
31 path = new Path({
32 segments: [event.point, event.point],
33 strokeColor: 'black',
34 strokeWidth: 5,
35 strokeCap: 'round'
36 });
37 prevPoint = path.firstSegment.point;
38 curPoint = path.lastSegment.point;
39 curHandleSeg = null;
40 }
41
42 var curPoint, prevPoint, curHandleSeg;
43 function onMouseDrag(event) {
44 var point = event.point;
45 var diff = (point - prevPoint).abs();
46 if (diff.x < diff.y) {
47 curPoint.x = prevPoint.x;
48 curPoint.y = point.y;
49 } else {
50 curPoint.x = point.x;
51 curPoint.y = prevPoint.y;
52 }
53 var normal = curPoint - prevPoint;
54 normal.length = 1;
55 if (curHandleSeg) {
56 curHandleSeg.point = prevPoint + (normal * values.radius);
57 curHandleSeg.handleIn = normal * -handle;
58 }
59 var minDiff = Math.min(diff.x, diff.y);
60 if (minDiff > values.tolerance) {
61 var point = curPoint - (normal * values.radius);
62 var segment = new Segment(point, null, normal * handle);
63 path.insert(path.segments.length - 1, segment);
64 curHandleSeg = path.lastSegment;
65 // clone as we want the unmodified one:
66 prevPoint = curHandleSeg.point.clone();
67 path.add(curHandleSeg);
68 curPoint = path.lastSegment.point;
69 }
70 }
71 </script>
72</head>
73<body>
74 <canvas id="canvas" resize></canvas>
75</body>
76</html>
Note: See TracBrowser for help on using the repository browser.