particle.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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.model.animation_function(this);
  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(e){
  36. controller.hit_test(e, 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. }
  44. }
  45. window.ParticleView = ParticleView;
  46. }(window));