<commit_before><!DOCTYPE html>
<html>
<head>
	<title>Verlet physics</title>
	<style type="text/css">
		html, body {
			margin: 0;
			overflow: hidden;
			width: 100%;
			height: 100%;
			background-color: #111100;
		}
		canvas {
			width: 100%;
			height: 100%;
		}
	</style>
</head>
<body>

<script type="text/javascript">
	var Point = function (x, y) {
		this._position = {
			x: x||0,
			y: y||0
		};
		this._nextPosition = {
			x: this._position.x,
			y: this._position.y
		};
		this._previousPosition = {
			x: this._position.x,
			y: this._position.y
		};
		this.fixed = false;
	}

	Point.prototype.update = function() {
		if(this.fixed) {
			this._nextPosition.x = this._position.x;
			this._nextPosition.y = this._position.y;
		}
		else {
			var velX = this._nextPosition.x - this._previousPosition.x;
			var velY = this._nextPosition.y - this._previousPosition.y;
			 
			this._previousPosition.x = this._nextPosition.x;
			this._previousPosition.y = this._nextPosition.y;

			this._position.x = this._nextPosition.x = this._nextPosition.x + velX;
			this._position.y = this._nextPosition.y = this._nextPosition.y + velY;
		}
	}

	Point.prototype.draw = function(context) {
		context.beginPath();
		context.arc(this._position.x,this._position.y,1,0,Math.PI*2);
		context.fill();
	}
</script>

<script type="text/javascript">
	var Link = function(p1, p2, distance) {
		this.p1 = p1;
		this.p2 = p2;

		var dx = p2._position.x - p1._position.x;
		var dy = p2._position.y - p1._position.y;

		this._distance = Math.sqrt(dx * dx + dy * dy);
	}

	Link.prototype.update = function() {
		var diffX = this.p1._nextPosition.x - this.p2._nextPosition.x;
		var diffY = this.p1._nextPosition.y - this.p2._nextPosition.y;
		var distance = Math.sqrt(diffX * diffX + diffY * diffY);

		var difference = (this._distance - distance) / distance;
		 
		var translateX = diffX * 0.5 * difference;
		var translateY = diffY * 0.5 * difference;
		
		if(!this.p1.fixed) {
			this.p1._nextPosition.x += translateX;
			this.p1._nextPosition.y += translateY;
		}
		
		if(!this.p2.fixed) {
			this.p2._nextPosition.x -= translateX;
			this.p2._nextPosition.y -= translateY;
		}
	};

	Link.prototype.draw = function(context) {
		context.moveTo(this.p1._position.x,this.p1._position.y);
		context.lineTo(this.p2._position.x, this.p2._position.y);
	};
</script>

<script type="text/javascript">

	var App = function () {
		this.SPACE = 20

		this.COLUMNS = 40;
		this.ROWS = 30;

		this.canvas = document.createElement('canvas');
		this.canvas.width = window.innerWidth;
		this.canvas.height = window.innerHeight;

		this.context = this.canvas.getContext('2d');

		this.points = [];
		this.links = [];

		this.width = this.SPACE * this.COLUMNS;
		this.height = this.SPACE * this.ROWS;

		var offsetX = (window.innerWidth - this.width) * .5;
		var offsetY = (window.innerHeight - this.height) * .5;

		for (var j = 0; j < this.ROWS; j++) {
			for (var i = 0; i < this.COLUMNS; i++) {
				var point = new Point(i * this.SPACE + offsetX, j * this.SPACE + 100);
				if(i != 0) this.links.push(new Link(point, this.points[j * this.COLUMNS + i - 1]));
				if(j != 0) this.links.push(new Link(point, this.points[(j - 1) * this.COLUMNS + i]));
				if(Math.random() > .99) point.fixed = true;
				this.points.push(point);
			}
		};

		this.mouse = {x:0, y:0};

		this.update();

		window.addEventListener('mousemove', this.onMouseMove.bind(this));
		window.addEventListener('resize', this.resize);
	}

	App.prototype.onMouseMove = function(e) {
		this.mouse.x = e.pageX;
		this.mouse.y = e.pageY;
	};

	App.prototype.update = function() {
		requestAnimationFrame(this.update.bind(this));

		this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

		for (var i = this.points.length - 1; i >= 0; i--) {
			var point = this.points[i];
			var dx = point._position.x - this.mouse.x;
			var dy = point._position.y - this.mouse.y;
			var dist = Math.sqrt(dx * dx + dy * dy);
			if (dist < 100) {
				point._nextPosition.x += dx * (1 - dist / 100)
				point._nextPosition.y += dy * (1 - dist / 100)
			};
		};

		// update (order matter)
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i]._nextPosition.y += 0.981; // Gravity
		for (var j = 0; j < 3; j++) {
			for (var i = this.links.length - 1; i >= 0; i--) this.links[i].update();
			for (var i = 0; i < this.links.length; i++) this.links[i].update();
		};
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i].update();

		// draw
		this.context.globalCompositeOperation = 'screen';
		this.context.fillStyle = '#ffffff';
		this.context.strokeStyle = '#334444';
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i].draw(this.context);
		for (var i = this.links.length - 1; i >= 0; i--) this.links[i].draw(this.context);
		this.context.stroke();
	}

	App.prototype.resize = function() {
		if(this.timeout) clearTimeout(this.timeout);
		this.timeout = setTimeout(function () {
			window.location.reload();
		}, 100);
	};

</script>

<script type="text/javascript">
	var app = new App();
	document.body.appendChild(app.canvas);
</script>
</body>
</html><commit_msg>correct encoding bug<commit_after><!DOCTYPE html>
<html>
<head>
	<title>Verlet physics</title>
	<style type="text/css">
		html, body {
			margin: 0;
			overflow: hidden;
			width: 100%;
			height: 100%;
			background-color: #111100;
		}
		canvas {
			width: 100%;
			height: 100%;
		}
	</style>
</head>
<body>

<script type="text/javascript">
	var Point = function (x, y) {
		this._position = {
			x: x||0,
			y: y||0
		};
		this._nextPosition = {
			x: this._position.x,
			y: this._position.y
		};
		this._previousPosition = {
			x: this._position.x,
			y: this._position.y
		};
		this.fixed = false;
	}

	Point.prototype.update = function() {
		if(this.fixed) {
			this._nextPosition.x = this._position.x;
			this._nextPosition.y = this._position.y;
		}
		else {
			var velX = this._nextPosition.x - this._previousPosition.x;
			var velY = this._nextPosition.y - this._previousPosition.y;
			 
			this._previousPosition.x = this._nextPosition.x;
			this._previousPosition.y = this._nextPosition.y;

			this._position.x = this._nextPosition.x = this._nextPosition.x + velX;
			this._position.y = this._nextPosition.y = this._nextPosition.y + velY;
		}
	}

	Point.prototype.draw = function(context) {
		context.beginPath();
		context.arc(this._position.x,this._position.y,1,0,Math.PI*2);
		context.fill();
	}
</script>

<script type="text/javascript">
	var Link = function(p1, p2, distance) {
		this.p1 = p1;
		this.p2 = p2;

		var dx = p2._position.x - p1._position.x;
		var dy = p2._position.y - p1._position.y;

		this._distance = Math.sqrt(dx * dx + dy * dy);
	}

	Link.prototype.update = function() {
		var diffX = this.p1._nextPosition.x - this.p2._nextPosition.x;
		var diffY = this.p1._nextPosition.y - this.p2._nextPosition.y;
		var distance = Math.sqrt(diffX * diffX + diffY * diffY);

		var difference = (this._distance - distance) / distance;
		
		var translateX = diffX * 0.5 * difference;
		var translateY = diffY * 0.5 * difference;
		
		if(!this.p1.fixed) {
			this.p1._nextPosition.x += translateX;
			this.p1._nextPosition.y += translateY;
		}
		
		if(!this.p2.fixed) {
			this.p2._nextPosition.x -= translateX;
			this.p2._nextPosition.y -= translateY;
		}
	};

	Link.prototype.draw = function(context) {
		context.moveTo(this.p1._position.x,this.p1._position.y);
		context.lineTo(this.p2._position.x, this.p2._position.y);
	};
</script>

<script type="text/javascript">

	var App = function () {
		this.SPACE = 20

		this.COLUMNS = 40;
		this.ROWS = 30;

		this.canvas = document.createElement('canvas');
		this.canvas.width = window.innerWidth;
		this.canvas.height = window.innerHeight;

		this.context = this.canvas.getContext('2d');

		this.points = [];
		this.links = [];

		this.width = this.SPACE * this.COLUMNS;
		this.height = this.SPACE * this.ROWS;

		var offsetX = (window.innerWidth - this.width) * .5;
		var offsetY = (window.innerHeight - this.height) * .5;

		for (var j = 0; j < this.ROWS; j++) {
			for (var i = 0; i < this.COLUMNS; i++) {
				var point = new Point(i * this.SPACE + offsetX, j * this.SPACE + 100);
				if(i != 0) this.links.push(new Link(point, this.points[j * this.COLUMNS + i - 1]));
				if(j != 0) this.links.push(new Link(point, this.points[(j - 1) * this.COLUMNS + i]));
				if(Math.random() > .99) point.fixed = true;
				this.points.push(point);
			}
		};

		this.mouse = {x:0, y:0};

		this.update();

		window.addEventListener('mousemove', this.onMouseMove.bind(this));
		window.addEventListener('resize', this.resize);
	}

	App.prototype.onMouseMove = function(e) {
		this.mouse.x = e.pageX;
		this.mouse.y = e.pageY;
	};

	App.prototype.update = function() {
		requestAnimationFrame(this.update.bind(this));

		this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);

		for (var i = this.points.length - 1; i >= 0; i--) {
			var point = this.points[i];
			var dx = point._position.x - this.mouse.x;
			var dy = point._position.y - this.mouse.y;
			var dist = Math.sqrt(dx * dx + dy * dy);
			if (dist < 100) {
				point._nextPosition.x += dx * (1 - dist / 100)
				point._nextPosition.y += dy * (1 - dist / 100)
			};
		};

		// update (order matter)
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i]._nextPosition.y += 0.981; // Gravity
		for (var j = 0; j < 3; j++) {
			for (var i = this.links.length - 1; i >= 0; i--) this.links[i].update();
			for (var i = 0; i < this.links.length; i++) this.links[i].update();
		};
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i].update();

		// draw
		this.context.globalCompositeOperation = 'screen';
		this.context.fillStyle = '#ffffff';
		this.context.strokeStyle = '#334444';
		for (var i = this.points.length - 1; i >= 0; i--) this.points[i].draw(this.context);
		for (var i = this.links.length - 1; i >= 0; i--) this.links[i].draw(this.context);
		this.context.stroke();
	}

	App.prototype.resize = function() {
		if(this.timeout) clearTimeout(this.timeout);
		this.timeout = setTimeout(function () {
			window.location.reload();
		}, 100);
	};

</script>

<script type="text/javascript">
	var app = new App();
	document.body.appendChild(app.canvas);
</script>
</body>
</html>
{'fraction_non_alphanumeric': 0.17023273273273273, 'fraction_numerical': 0.021584084084084083, 'mean_word_length': 2.6621993127147765, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 55, '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': '6790280', 'n_tokens_mistral': 4429, 'n_tokens_neox': 3830, 'n_words': 779}