particle.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. (function(window) {
  2. function ParticleView(modelObject){
  3. createjs.Shape.call(this);
  4. this.model = modelObject;
  5. this.model.view = this;
  6. var dp = this.model.draw_properties;
  7. var cs = window.cell_size;
  8. this.graphics
  9. .beginRadialGradientFill(dp.colors, dp.ratios,
  10. dp.inner_center.x * cs, dp.inner_center.y * cs , dp.inner_radius * cs,
  11. dp.outer_center.x * cs, dp.outer_center.y * cs, dp.outer_radius * cs)
  12. .drawCircle(0, 0, cs * dp.outer_radius);
  13. // this.graphics.beginFill("red").drawCircle(0, 0, window.cell_size * 0.2 / 2);
  14. this.animate();
  15. }
  16. ParticleView.prototype = new createjs.Shape();
  17. ParticleView.prototype.update = function(){
  18. this.x = cell_size * this.model.position.x + cell_size / 2;
  19. this.y = cell_size * this.model.position.y + cell_size / 2;
  20. }
  21. ParticleView.prototype.animate = function(){
  22. if(this.model.target){
  23. var own_view = this;
  24. this.update();
  25. this.update = function(){};
  26. createjs.Tween.get(this).to(
  27. {
  28. x: cell_size * this.model.target.x + cell_size / 2,
  29. y: cell_size * this.model.target.y + cell_size / 2
  30. },
  31. // We do not want to have magnetically curved particles for now
  32. // {guide:{ path:[0,0, 0,200,200,200, 200,0,0,0] }},
  33. this.model.target.time - this.model.start_time
  34. )
  35. .addEventListener("change", function(){
  36. controller.hit_test(own_view.model);
  37. })
  38. .call(function(){
  39. own_view.update = ParticleView.prototype.update;
  40. own_view.model.position.x = own_view.model.target.x;
  41. own_view.model.position.y = own_view.model.target.y;
  42. });
  43. } else {
  44. createjs.Tween.get(this, {loop: true})
  45. .to({ scaleX: 0.9, scaleY: 1.1 }, 200)
  46. .to({ scaleX: 1.1, scaleY: 0.9 }, 200);
  47. }
  48. }
  49. window.ParticleView = ParticleView;
  50. }(window));