rocket equation
This is a rocket simulator
by Brenton Strine
HTML
<div class="world">
<div class="karman-line"></div>
</div>
CSS
.world {
position: relative;
width: 10000px;
height: 2100px;
background: linear-gradient(to top, #7db9e8 0%,#ffffff 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */;
border-bottom: solid 15px green;
}
.dot {
position: absolute;
min-width: 1px;
min-height: 1px;
}
.dot-ascending {
background: linear-gradient(to top left, transparent 49%, green 50%,transparent 51%);
}
.dot-descending {
background: linear-gradient(to bottom left, transparent 49%, red 50%,transparent 51%);
}
.dot::after {
content: "";
width: 2px;
height: 2px;
background-color: blue;
position: absolute;
top: -1px;
right: 0;
}
.dot-final {
width: 20px;
height: 0;
border-top: dashed 1px black;
background-color: white;
border-left-color: blue;
}
.dot-crash {
border: dotted 4px yellow;
background-color: #ff2600;
border-radius: 51%;
}
.max-height {
position: absolute;
left: 0;
right: 0;
height: 1px;
border-top: dashed 1px black;
background-color: white;
border-left-color: blue;
}
.max-height::after {
content: "Maximum Altitude Reached";
font-family: sans-serif;
padding-left: 50px;
position: relative;
top: -1.3em;
}
.karman-line {
position: absolute;
top: 1100px;
left: 0;
right: 0;
height: 1px;
border-top: dashed 1px blue;
background-color: white;
border-left-color: blue;
}
.karman-line::after {
content: "Karman Line";
font-family: sans-serif;
padding-left: 50px;
position: relative;
top: -1.3em;
}
JavaScript
console.clear();
var world = document.querySelector(".world");
var count = 0;
// Rocket Equastion
var consumption = 1; // unit per second
var efficiency = 100.1; // thrust per unit consumed
var maxThrust = consumption * efficiency;
console.log("MaxThrust: ", maxThrust);
var thrust = {x: maxThrust, y: 0}; // pixel per second
var gravity = -1; // pixel per second
var dryMass = 10; // pounds
var fuelMass = 90; //pounds
var weight = (dryMass + fuelMass) * gravity;
var twr = thrust.x/(weight*gravity); // thrust/weight ratio
var wind = 0; // non-accelerative
var velocity = {x: 0, y: 0};
var position = {x: 0, y: 0};
var oldPos = {x: 0, y: 0};
var maxTime = 300;
var maxHeight = 0;
var maxVelocity = {x:0, y:0};
var plotRocketAt = function(t) {
oldPos = {x:position.x, y:position.y};
t++;
if (fuelMass > 0) {
fuelMass = fuelMass - consumption;
} else {
// empty!
fuelMass = 0;
thrust.x = 0;
thrust.y = 0;
}
// Adjust thrust according to roll program
var thrustAdjustment = rollProgram(position.x);
var totalThrust = thrust.x + thrust.y;
thrust.x = totalThrust * thrustAdjustment.x;
thrust.y = totalThrust * thrustAdjustment.y;
// Calculating X
weight = (dryMass + fuelMass) * gravity;
twr = thrust.x / (weight*gravity);
position.x = (position.x + twr + gravity + velocity.x);
velocity.x = position.x - oldPos.x;
// Calculating Y
position.y = (position.y + velocity.y + thrust.y);
velocity.y = position.y - oldPos.y;
/* changeWind(position.y);
if (Math.abs(velocity.y) < Math.abs(wind)) {
velocity.y += wind;
} */
var adj = 0;
// if in free-fall
var pixelsPerSecond = position.y - oldPos.y;
var escapeVelocity = 3074.0709999999963;//3074.906696719976;//3074.688694454846;
if( (fuelMass) === 0) {
adj = pixelsPerSecond / escapeVelocity;
console.log("speed: " + pixelsPerSecond + " - adj: " + adj);
debugger;
}
// curvature adjustment
velocity.x = velocity.x + adj;
// calculate...