JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

JavaScript

var Position = (function () {
  function Position(x, y) {
    this.collisions = [];
    this.x = x;
    this.y = y;
    this.velocity = new Vector(0, 0);
    this.xMax = 100;
    this.yMax = 100;
    this.radius = 10;
    this.accel = new Vector(0, 0);
  }
  return Position;
})();
Position.prototype = {
  impact: function (point2) {
     
    var point1 = this;
    var normal = point1.toPoint(point2);
    var normal2 = point2.toPoint(point1);
    var tangent = new Vector(-normal.y, normal.x);
    var tangent2 = new Vector(-normal2.y, normal2.x);
      point1.velocity.mult(point1.radius);
      point2.velocity.mult(point2.radius);
    normal.norm();
    normal2.norm();
    tangent.norm();
    tangent2.norm();
    //var midpoint = new Vector(((point1.x + point2.x) / 2.0), (point1.y + point2.y) / 2.0);
    //  point1.x = midpoint.x - normal.x * (this.radius+1);
    //   point1.y = midpoint.y - normal.y * (this.radius+1);
    //  point2.x = midpoint.x - normal2.x * (point2.radius);
    // point2.y = midpoint.y - normal2.y * (point2.radius);
    var v1n = normal.dot(point1.velocity),
      v1t = tangent.dot(point1.velocity),
      v2n = normal2.dot(point2.velocity),
      v2t = tangent2.dot(point2.velocity);
    normal.mult(v2n); //normal.mult(point1.velocity.mag);
    normal2.mult(v1n); //normal2.mult(point2.velocity.mag);
    tangent.mult(v1t); //tangent.mult(point1.velocity.mag);
    tangent2.mult(v2t); //tangent2.mult(point2.velocity.mag);
    var newv1 = new Vector(-(normal.x) + (tangent.x), -(normal.y) + (tangent.y));
    var newv2 = new Vector(-(normal2.x) + (tangent2.x), -(normal2.y) + (tangent2.y));
    point1.setvelocity(newv1);
    point2.setvelocity(newv2);
            point1.velocity.div(point1.radius);
      point2.velocity.div(point2.radius);
  },
  checkBounds: function () {
    var maxx = this.xMax;
    var maxy = this.yMax;
    if(this.x <= this.radius) {
      this.x =this.radius+ (this.x-this.radius) * -1;
      this.velocity.x *= -1;
      //...