52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
class Vector{
|
|
constructor(x, y){
|
|
this.x = x;
|
|
this.y = y;
|
|
}
|
|
|
|
scalarProduct(other){
|
|
return this.x*other.x + this.y*other.y;
|
|
}
|
|
|
|
magnitude(){
|
|
return Math.sqrt(this.x^2 + this.y^2);
|
|
}
|
|
|
|
//vector product would be useless because the resultant would be in the z-axis
|
|
|
|
angle(other = new Vector(1, 0)){ //need some magnitude for origin vector to avoid division by 0
|
|
//cosθ = a.b/|a||b|
|
|
return Math.acos(this.scalarProduct(other)/(this.magnitude()*other.magnitude()));
|
|
}
|
|
}
|
|
|
|
class Asteroid{
|
|
constructor(size, position, edges=5){
|
|
this.size = size;
|
|
this.edges = edges;
|
|
this.position = position;
|
|
}
|
|
|
|
draw(ctx){
|
|
ctx.beginPath();
|
|
|
|
}
|
|
}
|
|
|
|
//initializing canvas
|
|
const canvas = document.getElementById("canvas");
|
|
|
|
canvas.width = window.innerWidth;
|
|
canvas.height = window.innerHeight;
|
|
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
function animate(){
|
|
requestAnimationFrame(animate);
|
|
}
|
|
|
|
animate();
|
|
|