particle.js 1.6 KB

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