particle.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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;
  16. this.y = cell_size * this.model.position.y;
  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. { x: cell_size * this.model.target.x, y: cell_size * this.model.target.y },
  25. // We do not want to have magnetically curved particles for now
  26. // {guide:{ path:[0,0, 0,200,200,200, 200,0,0,0] }},
  27. this.model.target.time - this.model.start_time
  28. )
  29. .addEventListener("change", function(e){
  30. controller.hit_test(e, own_view.model);
  31. })
  32. .call(function(){
  33. own_view.update = ParticleView.prototype.update;
  34. own_view.model.position.x = own_view.model.target.x;
  35. own_view.model.position.y = own_view.model.target.y;
  36. });
  37. }
  38. }
  39. window.ParticleView = ParticleView;
  40. }(window));