
function ParticleEmitter(point,velocity) {
   this.position     = point;
   this.velocity     = velocity;
	this.size         = 0;
	this.particleLife = -1;
	this.spread       = Math.PI / 15;
	this.emissionRate = 20;
	
   this.moveTo = function(point) {
      this.position = point;
   }

	this.addParticle = function(){
//		var particle = new Particle(this.position.copy(),this.velocity.jitter(ParticleEmitter.jitter));
		var particle = new Particle(
		   this.position.copy(),
		   Vector.fromAngle(this.velocity.getAngle() + this.spread - (Math.random() * this.spread * 2), this.velocity.getMagnitude())
      );
      particle.ttl = this.particleLife;
      return particle;
	};
   this.toString = function() {
      var coreAttributes = [
         this.position.toString(),
         this.velocity.toString(),
         this.size,
         this.particleLife,
         this.spread.toFixed(2),
         this.emissionRate
      ];
      return 'E' + coreAttributes.join(':');   
   }
}

ParticleEmitter.drawColor  = "#D14A6E";
ParticleEmitter.drawColor2 = "#D14A6E";
ParticleEmitter.jitter     = .05;

ParticleEmitter.fromString = function(string) {
   var parts = (string.substr(1).split(':'));
   var emitter = new ParticleEmitter();
   emitter.position     = Point.fromString(parts.shift());
   emitter.velocity     = Vector.fromString(parts.shift());
   emitter.size         = parseInt(parts.shift());
   emitter.particleLife = parseInt(parts.shift());
   emitter.spread       = parseFloat(parts.shift());
   emitter.emissionRate = parseInt(parts.shift().valueOf());
   return emitter;
}

