particle.js 1.8 KB

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