ropeballphysics

by Darby Rathbone

JavaScript

var Vector = (function () {
    function Vector(x, y) {
        this.x = x;
        this.y = y;
        this.prevmag = 1
    };
    return Vector
})();
Vector.prototype = {
    toString: function () {
        return "[" + this.x + "," + this.y + "]"
    },
    mag: function () {
        return Math.sqrt((this.x * this.x) + (this.y * this.y))
    },
    mult: function (k) {
        this.x = this.x * k;
        this.y = this.y * k;
        return this.toString()
    },
    div: function (k) {
        this.x = (this.x) / k;
        this.y = (this.y) / k;
        return this.toString()
    },
    norm: function () {
        this.prevmag = this.mag();
        this.div((this.mag()));
        return this.toString()
    },
    add: function (a) {
        this.x = this.x + a.x;
        this.y = this.y + a.y;
        return this.toString()
    },
    sub: function (a) {
        this.x = this.x - a.x;
        this.y = this.y - a.y;
        return this.toString()
    },
    direction: function () {
        return Math.atan2(this.y, this.x)
    },
    dot: function (a) {
        return (a.x * this.x) + (a.y * this.y)
    }
};
var Position = (function () {
    function Position(x, y) {
        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
})(),
    Spring = (function () {
        function Spring(k, d, a) {
            this.end1 = null;
            this.end2 = null;
            this.k = k;
            this.d = d;
            this.len = a
        };
        return Spring
    })();
Spring.prototype = {
    force: function () {
        return new Vector(this.k * (this.end1.x - this.end2.x - this.len), this.k * (this.end1.y - this.end2.y - this.len))
    },
    damper: function () {
        return (new Vector(this.d * (this.end1.velocity.x - this.end2.velocity.x), this.d * (this.end1.velocity.y -...