particle.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. createjs.Tween.get(this, {loop: true})
  15. .to({ scaleX: 0.9, scaleY: 1.1 }, 200)
  16. .to({ scaleX: 1.1, scaleY: 0.9 }, 200);
  17. }
  18. ParticleView.prototype = new createjs.Shape();
  19. ParticleView.prototype.update = function(){
  20. this.x = cell_size * this.model.position.x + cell_size / 2;
  21. this.y = cell_size * this.model.position.y + cell_size / 2;
  22. }
  23. ParticleView.prototype.animate = function(){
  24. if(this.model.target){
  25. var own_view = this;
  26. this.update();
  27. this.update = function(){};
  28. createjs.Tween.get(this).to(
  29. {
  30. x: cell_size * this.model.target.x + cell_size / 2,
  31. y: cell_size * this.model.target.y + cell_size / 2
  32. },
  33. // We do not want to have magnetically curved particles for now
  34. // {guide:{ path:[0,0, 0,200,200,200, 200,0,0,0] }},
  35. this.model.target.time - this.model.start_time
  36. )
  37. .addEventListener("change", function(e){
  38. controller.hit_test(e, own_view.model);
  39. })
  40. .call(function(){
  41. own_view.update = ParticleView.prototype.update;
  42. own_view.model.position.x = own_view.model.target.x;
  43. own_view.model.position.y = own_view.model.target.y;
  44. });
  45. }
  46. }
  47. window.ParticleView = ParticleView;
  48. }(window));