particle.js 1.7 KB

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