initialize/Rate.js

  1. (function(Proton, undefined) {
  2. /**
  3. * The number of particles per second emission (a [particle]/b [s]);
  4. * @namespace
  5. * @memberof! Proton#
  6. * @constructor
  7. * @alias Proton.Rate
  8. *
  9. * @param {Array | Number | Proton.Span} numpan the number of each emission;
  10. * @param {Array | Number | Proton.Span} timepan the time of each emission;
  11. * for example: new Proton.Rate(new Proton.Span(10, 20), new Proton.Span(.1, .25));
  12. */
  13. function Rate(numpan, timepan) {
  14. this.numPan = Proton.Util.initValue(numpan, 1);
  15. this.timePan = Proton.Util.initValue(timepan, 1);
  16. this.numPan = Proton.Util.setSpanValue(this.numPan);
  17. this.timePan = Proton.Util.setSpanValue(this.timePan);
  18. this.startTime = 0;
  19. this.nextTime = 0;
  20. this.init();
  21. }
  22. Rate.prototype = {
  23. /**
  24. * @method init
  25. * @memberof Proton#Proton.Rate
  26. * @instance
  27. */
  28. init : function() {
  29. this.startTime = 0;
  30. this.nextTime = this.timePan.getValue();
  31. },
  32. getValue : function(time) {
  33. this.startTime += time;
  34. if (this.startTime >= this.nextTime) {
  35. this.startTime = 0;
  36. this.nextTime = this.timePan.getValue();
  37. if (this.numPan.b == 1) {
  38. if (this.numPan.getValue(false) > 0.5)
  39. return 1;
  40. else
  41. return 0;
  42. } else {
  43. return this.numPan.getValue(true);
  44. }
  45. }
  46. return 0;
  47. }
  48. }
  49. Proton.Rate = Rate;
  50. })(Proton);