JSFiddle - React, Tailwind, and code Playground
HTML
<canvas tabindex="1" id="canvas" width="800" height="600"></canvas>
<script type="text/javascript">
var sample = new Sample();
sample.run();
</script>
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;
};
function floorFigure(figure, decimals) {
if (!decimals) decimals = 2;
var d = Math.pow(10, decimals);
return (parseInt(figure * d) / d).toFixed(decimals);
}
;
//---------------------------------------------------------------------------------------------------------------------
//Vector2
//---------------------------------------------------------------------------------------------------------------------
function Vector2(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,...