Published
Edited
Jun 5, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
state = {
let f = fuel;
let tu = upThrust;
let ts = sideThrust;

let du = r + 0.1;
let ds = 0;
let vu = 0;
let vs = 0;

yield { x: 0, y: -r, f };
while (running > 0 && du > r) {
if (f > 0) f -= Math.abs(tu) + Math.abs(ts);
else tu = ts = f = 0;

const au = tu - (r*r*gravity) / (du*du);
vu = vu + au*(1/60);
du += vu;

vs = vs + ts*(1/60);
ds += vs;
const z = ds/du - Math.PI/2;
const x = Math.cos(z) * du;
const y = Math.sin(z) * du;
yield { x, y, f };
}
}
Insert cell
Insert cell
rocket = d3.select(scene)
.selectAll('circle.rocket')
.data([state])
.join("circle")
.attr("class", "rocket")
.attr("cx", d => d.x)
.attr("cy", d => d.y)
.attr("r", r/50)
.attr("fill", "yellow");
Insert cell
fuelbar = d3.select(scene)
.selectAll("rect.fuelbar")
.data([state])
.join("rect")
.attr("class", "fuelbar")
.attr("x", -2*r)
.attr("y", -2*r)
.attr("width", d => d.f/fuel * 4*r)
.attr("height", r/8)
.attr("fill", "#c82027");
Insert cell
Insert cell
r = 6371; // radius of earth
Insert cell
gravity = 9.81
Insert cell
fuel = 10000
Insert cell
size = 400
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more