You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Shapes</title>
  6. <link rel="stylesheet" href="../css/style.css">
  7. <script type="text/javascript" src="../../dist/paper-full.js"></script>
  8. <script type="text/paperscript" canvas="canvas">
  9. if (window.Worker) { // Check if Browser supports the Worker API.
  10. var worker = new Worker("Worker.js");
  11. // Create two paths, and send them to the worker to perform a boolean
  12. // operation on them.
  13. var circle = new Path.Circle({
  14. center: [200, 200],
  15. radius: 100,
  16. fillColor: 'red'
  17. });
  18. var rectangle = new Path.Rectangle({
  19. point: [200, 200],
  20. size: [200, 200],
  21. fillColor: 'blue'
  22. });
  23. var data = [
  24. circle.exportJSON(),
  25. rectangle.exportJSON()
  26. ];
  27. console.log('Sent', data);
  28. worker.postMessage(data);
  29. // The worker sends the result back in a message, from which we can then
  30. // create a new path item and siplay it.
  31. worker.onmessage = function(event) {
  32. var data = event.data;
  33. if (data) {
  34. console.log('Received', data);
  35. var result = project.activeLayer.importJSON(data);
  36. result.fillColor = 'yellow';
  37. result.fillColor.alpha = 0.5;
  38. result.position += [400, 0];
  39. result.fullySelected = true;
  40. }
  41. };
  42. }
  43. </script>
  44. </head>
  45. <body>
  46. <canvas id="canvas" resize></canvas>
  47. </body>
  48. </html>