JSFiddle - React, Tailwind, and code Playground
HTML
<canvas id="canv" width="1000" height="800"></canvas>
JavaScript
var canvas = document.getElementById("canv");
var ctx = document.getElementById("canv").getContext("2d");
var FPS = 30;
var vector = function(x,y){
this.x = x;
this.y = y;
};
vector.prototype.sub = function(ve){
return new vector(this.x - ve.x, this.y - ve.y);
};
vector.prototype.subFloat = function(val){
return new vector(this.x - val, this.y - val);
};
vector.prototype.add = function(ve){
return new vector(this.x + ve.x, this.y + ve.y);
};
vector.prototype.addFloat = function(val){
return new vector(this.x + val, this.y + val);
};
vector.prototype.multFloat = function(val){
return new vector(this.x * val, this.y * val);
};
vector.prototype.dot = function(ve){
return this.x * ve.x + this.y * ve.y;
};
vector.prototype.mult = function(ve){
return new vector(this.x * ve.x, this.y * ve.y);
};
vector.prototype.divFloat = function(val){
return new vector(this.x / val, this.y / val);
};
vector.prototype.normalize = function(){
var length = Math.sqrt(this.x * this.x + this.y * this.y);
var x = this.x / length;
var y = this.y / length;
return new vector(x,y);
};
var circle = function(pos, radius, velocity){
this.pos = pos;
this.radius = radius;
this.velocity = velocity;
};
circle.prototype.intersect = function(){
var intersects = true;
for(var k = 0; k < segmentList.length; k++){
var seg = segmentList[k];
...