JSFiddle - React, Tailwind, and code Playground

HTML

<!DOCTYPE html>
<html>
<head>
<title>Physics</title>
</head>
<body>
<canvas tabindex="1" id="canvas" width="800" height="480"></canvas>
<script type="text/javascript">
    var sample = new Sample();
    sample.run();
</script>
</body>
</html>

JavaScript

// ---------------------------------------------------------------------------------------------------------------------
// Helper
// ---------------------------------------------------------------------------------------------------------------------
window.requestAnimFrame = (function () {
    return  window.requestAnimationFrame ||
            window.webkitRequestAnimationFrame ||
            window.mozRequestAnimationFrame ||
            window.oRequestAnimationFrame ||
            window.msRequestAnimationFrame ||
            function (callback) {
                window.setTimeout(callback, 1000 / 60);
            };
})();

Function.prototype.inheritsFrom = function (parentClassOrObject) {
    if (parentClassOrObject.constructor == Function) {
        //Normal Inheritance
        this.prototype = new parentClassOrObject;
        this.prototype.constructor = this;
        this.prototype.parent = parentClassOrObject.prototype;
    }
    else {
        //Pure Virtual Inheritance
        this.prototype = parentClassOrObject;
        this.prototype.constructor = this;
        this.prototype.parent = parentClassOrObject;
    }
    return this;
};

//---------------------------------------------------------------------------------------------------------------------
//Vector2
//---------------------------------------------------------------------------------------------------------------------
function Vec2(x, y) {
    return {
        x:x.x !== undefined && y === undefined ? x.x : x,
        y:x.y !== undefined && y === undefined ? x.y : y,
        halfX:function () {
            return this.x / 2;
        },
        halfY:function () {
            return this.y / 2;
        },
        dot:function (v) {
            return (this.x * v.x) + (this.y * v.y);
        },
        sub:function (x, y) {
            if (x.x !== undefined && x.y !== undefined) {
                return Vec2(this.x - x.x, this.y - x.y);
            } else if (y !== undefined) {
              ...