particle.js 1.8 KB

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