delete

delete

by electronoob

HTML

<canvas id="game" width="600" height="600"></canvas>

CSS

canvas {
  border: solid 1px #000;
}

JavaScript

var theCanvas = document.getElementById("game");
var ctx = theCanvas.getContext("2d");
var start = new Vector(10,10);
var end = new Vector(50,50);
var position = new Vector(10,10);

var grid = [];
for(let x = 0;x<60;x++) {
	grid[x] = [];
  for(let y = 0;y<60;y++) {
		grid[x][y] = 0;
  }
}
grid[start.x][start.y] = 1;
grid[end.x][end.y] = 1;
function draw () {
	ctx.clearRect(0,0,600,600);
  for(let x = 0;x<60;x++) {
    for(let y = 0;y<60;y++) {
    	if(grid[x][y] == 1) {
      	ctx.fillStyle = "black";
        ctx.fillRect(x*10,y*10,10,10);
      }
    }
  }
	window.requestAnimationFrame(draw);
}

draw();
console.log(start.heading() * 180 / Math.PI);

setInterval(() => {
	//console.log("d");
},100);




function Vector(x = 0, y = 0) {
    this.x = x;
    this.y = y;
    this.heading = function() {
    	return Math.atan2(this.y, this.x);
    };
    this.sub = function(b) {
        this.x -= b.x;
        this.y -= b.y;
    };
    this.add = function(b) {
        this.x += b.x;
        this.y += b.y;
    };
    this.mag = function() {
        return Math.sqrt(Math.abs(this.x) ^ 2 + Math.abs(this.y) ^ 2);
    };
    this.magsq = function() {
        return Math.abs(this.x) ^ 2 + Math.abs(this.y) ^ 2;
    };
    this.div = function(value) {
        this.x /= value;
        this.y /= value;
    };
    this.mul = function(value) {
        this.x *= value;
        this.y *= value;
    };
    this.setMag = function(value) {
        var m = this.mag();
        if (m !== 0 && m != 1) {
            this.div(m);
        }
        this.mul(value);
    };
    this.hypot = function(b) {
        return Math.hypot(this.x - b.x, this.y - b.y);
    };
    this.lerp = function(b, step) {
        var a = new Vector(this.x, this.y);
        b.sub(a);
        b.mul(step);
        b.add(a);
        return b;
    };
}