Hello!
I've put together a little orbital motion code but it seems to have trouble running in glowscript. This is strange as I can run it in Jupyter notebook (albeit slowly) so I'm not really sure what the error is and, or, how to fix it. Any thoughts? The code is attached below:
Web VPython 3.2
m1 = 1.988e30
m2 = 1.988e30
mu = (m1*m2)/(m1+m2)
G = 6.67e-11
a = 1.5e11
ecc = 0
aph = a*(1+ecc)
x0 = (m2*aph)/(m1+m2)
X0 = -(m1*aph)/(m1+m2)
y0 = 0
Y0 = 0
vel1 = ((G*mu/a)*(m2/m1)*((1-ecc)/(1+ecc)))**0.5
vel2 = -((G*mu/a)*(m2/m1)*((1-ecc)/(1+ecc)))**0.5 * (m1/m2)
canvas(background=color.white,height=800, width=1520)
bh = sphere(pos=vector(x0,0,0), radius=0.1e10, color=color.black,
make_trail=True, trail_type='curve', interval=1000)
bh.p = vector(0, vel1, 0) * m1
star = sphere(pos=vector(X0,0,0), radius=1e10, color=vector(0.98039,0.3921568,0.12549),
make_trail=True, trail_type='curve', interval=1000)
star.p = vector(0,vel2,0) * m2
dt = 10
while True:
rate(200000)
r = star.pos-bh.pos
F = 6.67e-11 * m1 * m2 * r.hat/mag(r)**2
bh.p = bh.p + F*dt
star.p = star.p - F*dt
bh.pos = bh.pos + (bh.p/m1) * dt
star.pos = star.pos + (star.p/m2) * dt