fake orbits

by jcubed111

HTML

<canvas id="main"></canvas>

CSS

body{
    margin: 0;
    padding: 0;
    overflow: hidden;
}

JavaScript

var canvas = document.getElementById("main");
var ctx = canvas.getContext('2d');
var z = 10;
var BigG = 1.0;

document.addEventListener('wheel', e => {
	z *= e.deltaY > 0 ? Math.sqrt(0.5) : Math.sqrt(2.0);
});

var planets = [];

function project({x, y, z}) {
	return {x: x, y: y};
}

class Planet{
	constructor({
    	radius, 
        mass, 
        orbits, 
        periDist, 
        apDist, 
        periTheta = 0, 
        color = "#f00", 
        drawPath = true, 
        inclination = 0.0, 
        clockwise = false,
        type = "planet",
    }) {
        this.radius = radius;
        this.mass = mass;
        this.orbits = orbits;
        this.periDist = periDist;
        this.apDist = apDist;
        this.periTheta = periTheta;
        this.color = color;
        this.drawPath = drawPath;
        this.inclination = inclination;
        this.clockwise = clockwise;
        this.type = type;
        
        if(this.periDist > this.apDist) {
            this.periDist = apDist;
            this.apDist = periDist;
        }
        
        this.thetaCorrection = Math.PI / this.calculateThetaFromM(Math.PI);
    }
    
    eccentricity() {
    	return (this.apDist - this.periDist) / (this.periDist + this.apDist);
    }
    
    ellipseA() {
    	return (this.periDist + this.apDist) / 2.0;
    }
    
    semiMinor() {
    	return Math.sqrt(this.periDist * this.apDist);
    }
    
    semiLatusRectum() {
    	return this.periDist * (1 + this.eccentricity());
    }
    
    orbitsMass() {
    	if(typeof this.orbits == 'number') {
        	return this.orbits;
        }else{
        	return this.orbits.mass;
        }
    }
    
    orbitsPosAtTime(t) {
    	if(typeof this.orbits == 'number') {
        	return {x: 0, y: 0, z: 0};
        }else{
        	return this.orbits.posAtTime(t);
        }
    }
    
    period() {
    	return 2.0 * Math.PI * Math.sqrt(this.ellipseA()**3 / BigG / this.orbitsMass());
    }
    
    render(ctx, t) {
    	/* current */
       ...