geometry.html 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Animate</title>
  5. <script src="../dev-lib/sea.js"></script>
  6. <script>
  7. seajs.config({
  8. base: '../src'
  9. });
  10. define('start', function(require) {
  11. var Paper = require('graphic/paper');
  12. var Path = require('graphic/path');
  13. require('animate/pathanimator');
  14. var g = require('graphic/geometry');
  15. var Matrix = require('graphic/matrix');
  16. var pathData = g.transformPath('M283.962,257.412 L229.347,253.275 194.977,295.919 182.036,242.699 130.857,223.189 177.473,194.435 180.213,139.733 221.965,175.182 274.837,160.884 254.025,211.547 Z', new Matrix().scale(0.3).translate(400, 0));
  17. var Group = require('graphic/group');
  18. require('animate/motionanimator');
  19. var path1 = new Path().stroke('blue').translate(-300, 0);
  20. var path2 = new Path().stroke('red', 5).translate(-300, 0);
  21. var paper = new Paper(document.body).setHeight(800);
  22. paper.addShapes([path1, path2]);
  23. var pathData2 = 'M615.992,227.397c0,48.272-43.234,87.405-96.565,87.405 s-96.565-39.132-96.565-87.405c0-22.737,9.631-33.72,25.351-49.267c5.705-5.642-7.917-57.699-0.763-61.832 c5.962-3.445,36.82,36.75,43.511,34.351c40.458-14.504,51.562-2.07,61.069,0.763c11.853,3.532,43.345-29.261,52.672-22.137c7.952,6.074-8.23,44.582-2.784,52.659C610.847,195.18,615.992,210.745,615.992,227.397z';
  24. var aligned = g.alignCurve(pathData, pathData2);
  25. path1.setPathData(aligned[0]);
  26. path1.fxPath(pathData2, 3000, 'easeInOutElastic');
  27. var t = 0.1;
  28. function update() {
  29. t += 0.003;
  30. var sub = g.subPath(pathData2, t, t - 0.05).concat(g.subPath(pathData2, t + 0.55, t + 0.5));
  31. path2.setPathData(sub);
  32. requestAnimationFrame(update);
  33. }
  34. update();
  35. var triangle = new Path().setPathData('M0,-15L15,0,0,15Z').fill('green');
  36. triangle.motion(path1, 4000, 'linear').timeline().repeat(10000);
  37. paper.addShape(new Group().addShape(triangle).translate(-300, 0));
  38. window.g = g;
  39. });
  40. seajs.use('start');
  41. </script>
  42. </head>
  43. <body>
  44. </body>
  45. </html>