<commit_before>//Particle component
//Based on Parcycle by Mr. Speaker, licensed under the MIT,
//Ported by <NAME>
//**This is canvas only & won't do anything if the browser doesn't support it!**

Crafty.c("particles", {
	init: function () {
		//nothing to do here...
	},
	particles: function (options) {

		if (!Crafty.support.canvas) return this;

		//If we drew on the main canvas, we'd have to redraw 
		//potentially huge sections of the screen every frame
		//So we create a separate canvas, where we only have to redraw 
		//the changed particles.
		var c, ctx, relativeX, relativeY, bounding;

		c = document.createElement("canvas");
		c.width = Crafty.viewport.width;
		c.height = Crafty.viewport.height;
		c.style.position = 'absolute';

		Crafty.stage.elem.appendChild(c);

		ctx = c.getContext('2d');

		this._Particles.init(options);

		relativeX = this.x + Crafty.viewport.x;
		relativeY = this.y + Crafty.viewport.y;
		this._Particles.position = this._Particles.vectorHelpers.create(relativeX, relativeY);

		var oldViewport = {x: Crafty.viewport.x, y:Crafty.viewport.y};
		
		this.bind('enterframe', function () {
			relativeX = this.x + Crafty.viewport.x;
			relativeY = this.y + Crafty.viewport.y;
			this._Particles.viewportDelta = {x: Crafty.viewport.x - oldViewport.x, y: Crafty.viewport.y - oldViewport.y};

			oldViewport = {x: Crafty.viewport.x, y:Crafty.viewport.y};
				
			this._Particles.position = this._Particles.vectorHelpers.create(relativeX, relativeY);

			//Selective clearing
			if (typeof Crafty.DrawManager.boundingRect == 'function') {
				bounding = Crafty.DrawManager.boundingRect(this._Particles.register);
				if (bounding) ctx.clearRect(bounding._x, bounding._y, bounding._w, bounding._h);
			} else {
				ctx.clearRect(0, 0, Crafty.viewport.width, Crafty.viewport.height);
			}

			//This updates all particle colors & positions
			this._Particles.update();

			//This renders the updated particles
			this._Particles.render(ctx);
		});
		return this;
	},
	_Particles: {
		presets: {
			maxParticles: 150,
			particles: [],
			active: true,

			// Properties
			size: 18,
			sizeRandom: 4,
			speed: 1,
			speedRandom: 1.2,
			lifeSpan: 29,
			lifeSpanRandom: 7,
			angle: 65,
			angleRandom: 34,
			startColour: [255, 131, 0, 1],
			startColourRandom: [48, 50, 45, 0],
			endColour: [245, 35, 0, 0],
			endColourRandom: [60, 60, 60, 0],
			sharpness: 20,
			sharpnessRandom: 10,
			spread: 10,
			particleCount: 0,
			elapsedFrames: 0,
			duration: -1,
			emissionRate: 0,
			emitCounter: 0,
			particleIndex: 0,
			fastMode: false,
			gravity:{x: 0, y: 0.1}
		},


		init: function (options) {
			this.position = this.vectorHelpers.create(0, 0);
			if (typeof options == 'undefined') var options = {};

			//Create current config by mergin given options and presets.
			for (key in this.presets) {
				this[key] = options[key] || this.presets[key];
			}

			this.emissionRate = this.maxParticles / this.lifeSpan;
			this.positionRandom = this.vectorHelpers.create(this.spread, this.spread);
		},

		addParticle: function () {
			if (this.particleCount == this.maxParticles) {
				return false;
			}

			// Take the next particle out of the particle pool we have created and initialize it	
			var particle = new this.particle(this.vectorHelpers);
			this.initParticle(particle);
			this.particles[this.particleCount] = particle;
			// Increment the particle count
			this.particleCount++;

			return true;
		},

		initParticle: function (particle) {
			var RANDM1TO1 = function () {
				return Math.random() * 2 - 1;
			};

			particle.position.x = this.position.x + this.positionRandom.x * RANDM1TO1();
			particle.position.y = this.position.y + this.positionRandom.y * RANDM1TO1();

			var newAngle = (this.angle + this.angleRandom * RANDM1TO1()) * (Math.PI / 180); // convert to radians
			var vector = this.vectorHelpers.create(Math.cos(newAngle), Math.sin(newAngle)); // Could move to lookup for speed
			var vectorSpeed = this.speed + this.speedRandom * RANDM1TO1();
			particle.direction = this.vectorHelpers.multiply(vector, vectorSpeed);

			particle.size = this.size + this.sizeRandom * RANDM1TO1();
			particle.size = particle.size < 0 ? 0 : ~~particle.size;
			particle.timeToLive = this.lifeSpan + this.lifeSpanRandom * RANDM1TO1();

			particle.sharpness = this.sharpness + this.sharpnessRandom * RANDM1TO1();
			particle.sharpness = particle.sharpness > 100 ? 100 : particle.sharpness < 0 ? 0 : particle.sharpness;
			// internal circle gradient size - affects the sharpness of the radial gradient
			particle.sizeSmall = ~~ ((particle.size / 200) * particle.sharpness); //(size/2/100)
			var start = [
				this.startColour[0] + this.startColourRandom[0] * RANDM1TO1(),
				this.startColour[1] + this.startColourRandom[1] * RANDM1TO1(),
				this.startColour[2] + this.startColourRandom[2] * RANDM1TO1(),
				this.startColour[3] + this.startColourRandom[3] * RANDM1TO1()
				];

			var end = [
				this.endColour[0] + this.endColourRandom[0] * RANDM1TO1(),
				this.endColour[1] + this.endColourRandom[1] * RANDM1TO1(),
				this.endColour[2] + this.endColourRandom[2] * RANDM1TO1(),
				this.endColour[3] + this.endColourRandom[3] * RANDM1TO1()
				];<commit_msg>2 small fixes for particles<commit_after>//Particle component
//Based on Parcycle by Mr. Speaker, licensed under the MIT,
//Ported by <NAME>
//**This is canvas only & won't do anything if the browser doesn't support it!**

Crafty.c("particles", {
	init: function () {
		//nothing to do here...
	},
	particles: function (options) {

		if (!Crafty.support.canvas) return this;

		//If we drew on the main canvas, we'd have to redraw 
		//potentially huge sections of the screen every frame
		//So we create a separate canvas, where we only have to redraw 
		//the changed particles.
		var c, ctx, relativeX, relativeY, bounding;

		c = document.createElement("canvas");
		c.width = Crafty.viewport.width;
		c.height = Crafty.viewport.height;
		c.style.position = 'absolute';

		Crafty.stage.elem.appendChild(c);

		ctx = c.getContext('2d');

		this._Particles.init(options);

		relativeX = this.x + Crafty.viewport.x;
		relativeY = this.y + Crafty.viewport.y;
		this._Particles.position = this._Particles.vectorHelpers.create(relativeX, relativeY);

		var oldViewport = {x: Crafty.viewport.x, y:Crafty.viewport.y};
		
		this.bind('enterframe', function () {
			relativeX = this.x + Crafty.viewport.x;
			relativeY = this.y + Crafty.viewport.y;
			this._Particles.viewportDelta = {x: Crafty.viewport.x - oldViewport.x, y: Crafty.viewport.y - oldViewport.y};

			oldViewport = {x: Crafty.viewport.x, y:Crafty.viewport.y};
				
			this._Particles.position = this._Particles.vectorHelpers.create(relativeX, relativeY);

			//Selective clearing
			if (typeof Crafty.DrawManager.boundingRect == 'function') {
				bounding = Crafty.DrawManager.boundingRect(this._Particles.register);
				if (bounding) ctx.clearRect(bounding._x, bounding._y, bounding._w, bounding._h);
			} else {
				ctx.clearRect(0, 0, Crafty.viewport.width, Crafty.viewport.height);
			}

			//This updates all particle colors & positions
			this._Particles.update();

			//This renders the updated particles
			this._Particles.render(ctx);
		});
		return this;
	},
	_Particles: {
		presets: {
			maxParticles: 150,
			particles: [],
			active: true,

			// Properties
			size: 18,
			sizeRandom: 4,
			speed: 1,
			speedRandom: 1.2,
			lifeSpan: 29,
			lifeSpanRandom: 7,
			angle: 65,
			angleRandom: 34,
			startColour: [255, 131, 0, 1],
			startColourRandom: [48, 50, 45, 0],
			endColour: [245, 35, 0, 0],
			endColourRandom: [60, 60, 60, 0],
			sharpness: 20,
			sharpnessRandom: 10,
			spread: 10,
			particleCount: 0,
			elapsedFrames: 0,
			duration: -1,
			emissionRate: 0,
			emitCounter: 0,
			particleIndex: 0,
			fastMode: false,
			gravity:{x: 0, y: 0.1}
		},


		init: function (options) {
			this.position = this.vectorHelpers.create(0, 0);
			if (typeof options == 'undefined') var options = {};

			//Create current config by mergin given options and presets.
			for (key in this.presets) {
				if (typeof options[key] != 'undefined') this[key] = options[key];
				else this[key] = this.presets[key];
			}

			this.emissionRate = this.maxParticles / this.lifeSpan;
			this.positionRandom = this.vectorHelpers.create(this.spread, this.spread);
		},

		addParticle: function () {
			if (this.particleCount == this.maxParticles) {
				return false;
			}

			// Take the next particle out of the particle pool we have created and initialize it	
			var particle = new this.particle(this.vectorHelpers);
			this.initParticle(particle);
			this.particles[this.particleCount] = particle;
			// Increment the particle count
			this.particleCount++;

			return true;
		},

		initParticle: function (particle) {
			var RANDM1TO1 = function () {
				return Math.random() * 2 - 1;
			};

			particle.position.x = this.position.x + this.positionRandom.x * RANDM1TO1();
			particle.position.y = this.position.y + this.positionRandom.y * RANDM1TO1();

			var newAngle = (this.angle + this.angleRandom * RANDM1TO1()) * (Math.PI / 180); // convert to radians
			var vector = this.vectorHelpers.create(Math.sin(newAngle), -Math.cos(newAngle)); // Could move to lookup for speed
			var vectorSpeed = this.speed + this.speedRandom * RANDM1TO1();
			particle.direction = this.vectorHelpers.multiply(vector, vectorSpeed);

			particle.size = this.size + this.sizeRandom * RANDM1TO1();
			particle.size = particle.size < 0 ? 0 : ~~particle.size;
			particle.timeToLive = this.lifeSpan + this.lifeSpanRandom * RANDM1TO1();

			particle.sharpness = this.sharpness + this.sharpnessRandom * RANDM1TO1();
			particle.sharpness = particle.sharpness > 100 ? 100 : particle.sharpness < 0 ? 0 : particle.sharpness;
			// internal circle gradient size - affects the sharpness of the radial gradient
			particle.sizeSmall = ~~ ((particle.size / 200) * particle.sharpness); //(size/2/100)
			var start = [
				this.startColour[0] + this.startColourRandom[0] * RANDM1TO1(),
				this.startColour[1] + this.startColourRandom[1] * RANDM1TO1(),
				this.startColour[2] + this.startColourRandom[2] * RANDM1TO1(),
				this.startColour[3] + this.startColourRandom[3] * RANDM1TO1()
				];

			var end = [
				this.endColour[0] + this.endColourRandom[0] * RANDM1TO1(),
				this.endColour[1] + this.endColourRandom[1] * RANDM1TO1(),
				this.endColour[2] + this.endColourRandom[2] * RANDM1TO1(),
				this.endColour[3] + this.endColourRandom[3] * RANDM1TO1()
				];
{'fraction_non_alphanumeric': 0.1356463878326996, 'fraction_numerical': 0.02576045627376426, 'mean_word_length': 3.5329599310641964, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6390085', 'n_tokens_mistral': 4306, 'n_tokens_neox': 3557, 'n_words': 844}