Advertisement
Guest User

Untitled

a guest
Apr 9th, 2013
1,254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html>
  3.  
  4.   <head>
  5.     <meta charset="utf-8">
  6.     <style type="text/css">
  7.       #myCanvas {
  8.         border: 1px solid #c3c3c3;
  9.       }
  10.       #xycoordinates {
  11.         font: 9pt sans-serif;
  12.       }
  13.     </style>
  14.     <script type="text/javascript" src="http://paperjs.org/static/js/paper.js"></script>
  15.   </head>
  16.  
  17.   <body>
  18.     <canvas id="myCanvas" width="256" height="128"></canvas>
  19.     <div id="xycoordinates"></div>
  20.     <script type="text/javascript">
  21.       var canvas = document.getElementById("myCanvas"); // Get canvas
  22.  
  23.        // Some initialisation stuff to make things work out of PaperScript context
  24.        // Have to have things to be done this way because jsfiddle don't allow to save source with script type="text/paperscript"
  25.       paper.install(window);
  26.       paper.setup(canvas);
  27.  
  28.       var myPath = new paper.Path.Circle([64, 64], 32); // Red one, with 'pointer' cursor on it
  29.       myPath.style = {
  30.         fillColor: '#FF0000'
  31.       };
  32.       var scndPath = new paper.Path.Circle([192, 64], 32); // Green one, without cursor accent
  33.       scndPath.style = {
  34.         fillColor: '#00FF00'
  35.       };
  36.       paper.view.draw(); // Have to call manually when working from JavaScript directly
  37.  
  38.       var hitOptions = { // Trigger hit only on 'fill' part of the path with 0 tolerance
  39.         segments: false,
  40.         stroke: false,
  41.         fill: true,
  42.         tolerance: 0
  43.       };
  44.  
  45.       var tooll = new paper.Tool(); // Again manually. Life is much easier with script type="text/paperscript"
  46.       tooll.onMouseMove = function (event) { // Installig paperjs event
  47.         var x = event.point.x;
  48.         var y = event.point.y;
  49.  
  50.         document.getElementById("xycoordinates").innerHTML = "Coordinates: (" + x + "," + y + ")";
  51.  
  52.         var hitResult = myPath.hitTest(event.point, hitOptions); // isPointInPath
  53.  
  54.         if (hitResult) {
  55.           document.body.style.cursor = "pointer";
  56.         } else {
  57.           document.body.style.cursor = "default";
  58.         }
  59.       };
  60.     </script>
  61.   </body>
  62.  
  63. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement