animate.html 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Group = require('graphic/group');
  13. var Path = require('graphic/path');
  14. var Color = require('graphic/color');
  15. var Text = require('graphic/text');
  16. var Draggable = require('../demo/public/draggable');
  17. var Animator = require('animate/animator');
  18. var Matrix = require('graphic/matrix');
  19. var Circle = require('graphic/circle');
  20. var Rect = require('graphic/rect');
  21. var Use = require('graphic/use');
  22. require('animate/translateanimator');
  23. require('animate/rotateanimator');
  24. require('animate/scaleanimator');
  25. require('animate/opacityanimator');
  26. require('core/class').extendClass(Paper, Draggable);
  27. var paper = new Paper(document.body);
  28. paper.setViewBox(0, 0, 1200, 600).drag();
  29. var bounce = new Animator(0, 400, function(target, y, timeline) {
  30. target.translate(0, timeline.getDelta());
  31. });
  32. var colorChanger = new Animator({
  33. beginValue: function(target) {
  34. return target.color;
  35. },
  36. finishValue: function(target) {
  37. return target.color.inc('h', 90)
  38. },
  39. setter: function(target, color) {
  40. target.fill(color);
  41. }
  42. });
  43. function atternuate(e) {
  44. //e.target.scale(0.6 + Math.random() * 0.6, e.target.getCenterX(), e.target.getCenterY());
  45. }
  46. //paper.addResource(rect);
  47. for(var i = 0; i < 200; i++) {
  48. var color = Color.createHSL(i * 30 % 360, 80, 50);
  49. var copy = new Rect(5, 20, 0, 10).translate( i * 5, 0 );
  50. copy.color = color;
  51. copy.fill(color);
  52. paper.addShape(copy);
  53. bounce.start(copy, 500, 'easeInQuad', Math.random() * 5000).repeat(true, true).on('rollback', atternuate);
  54. colorChanger.start(copy, 500, 'linear').repeat(true, true);
  55. copy.fxTranslate(0, 300, '1s', 'easeInQuad', Math.random() * 5000);
  56. copy.fxTranslate(100, -100, '0.1s', 'easeOutQuad');
  57. copy.fxRotate(1080, '2s', 'linear', 500);
  58. copy.fxScale(.5, .5, '0.8s', 'easeInElastic');
  59. copy.fxTranslate(100, -200, '0.8s', 'easeOutElastic');
  60. copy.fadeOut(300).fadeIn(1000).fadeTo(.5, 100);
  61. }
  62. });
  63. seajs.use('start');
  64. </script>
  65. </head>
  66. <body>
  67. </body>
  68. </html>