This program below is an attempt to implement the one here : http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/BinaryStar-VPython/edit
but it doesnt work.. This was on Chrome beta 42.0 on Ubuntu 14.04
Notes:
(a) I replaced the while True with the recursive version as in Pyschool's bounce
(a) There seem to be some associative rule issues : the expression
F = G * giant.mass * dwarf.mass * norm(r) / mag2(r)
doesnt work even with r.norm() and r.mag2() so that I had to use :
coeff = G * giant.mass * dwarf.mass/r.mag2()
F = r.norm() * coeff
to make it work..
(b) Initially I had the make_trail params to the spheres left as in the original vPython. But the program seemed to be executing with canvas/scene completely blank. Since I recall reading somewhere that make_trail had issues in brython-glow, I removed the make_trail params but still the canvas/scene is blank..
from glow import *
glow('pydiv')
scene = canvas()
scene.forward = vec(0,-.3,-1).to_glowscript()
G = 6.7e-11
giant = sphere(pos=vec(-1e11,0,0), radius=2e10, color=color.red)
giant.mass = 2e30
giant.p = vec(0, 0, -1e4) * giant.mass
dwarf = sphere(pos=vec(1.5e11,0,0), radius=1e10, color=color.yellow)
dwarf.mass = 1e30
dwarf.p = vec(0,0,0)-giant.p
r = dwarf.pos - giant.pos
coeff = G * giant.mass * dwarf.mass/r.mag2()
q = r.norm()*coeff
print("q",q)
dt = 1e5
def move():
r = dwarf.pos - giant.pos
#F = G * giant.mass * dwarf.mass * norm(r) / mag2(r)
coeff = G * giant.mass * dwarf.mass/r.mag2()
F = r.norm() * coeff
giant.p = giant.p + F_dt
dwarf.p = dwarf.p - F_dt
giant.pos = giant.pos + (giant.p/giant.mass) * dt
dwarf.pos = dwarf.pos + (dwarf.p/dwarf.mass) * dt
print("start exec")
move()
This program below is an attempt to implement the one here : http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/BinaryStar-VPython/edit
but it doesnt work.. This was on Chrome beta 42.0 on Ubuntu 14.04
Notes:
(a) I replaced the while True with the recursive version as in Pyschool's bounce
(a) There seem to be some associative rule issues : the expression
F = G * giant.mass * dwarf.mass * norm(r) / mag2(r)
doesnt work even with r.norm() and r.mag2() so that I had to use :
coeff = G * giant.mass * dwarf.mass/r.mag2()
F = r.norm() * coeff
to make it work..
(b) Initially I had the make_trail params to the spheres left as in the original vPython. But the program seemed to be executing with canvas/scene completely blank. Since I recall reading somewhere that make_trail had issues in brython-glow, I removed the make_trail params but still the canvas/scene is blank..
from glow import *
glow('pydiv')
scene = canvas()
scene.forward = vec(0,-.3,-1).to_glowscript()
G = 6.7e-11
giant = sphere(pos=vec(-1e11,0,0), radius=2e10, color=color.red)
giant.mass = 2e30
giant.p = vec(0, 0, -1e4) * giant.mass
dwarf = sphere(pos=vec(1.5e11,0,0), radius=1e10, color=color.yellow)
dwarf.mass = 1e30
dwarf.p = vec(0,0,0)-giant.p
r = dwarf.pos - giant.pos
coeff = G * giant.mass * dwarf.mass/r.mag2()
q = r.norm()*coeff
print("q",q)
dt = 1e5
def move():
r = dwarf.pos - giant.pos
#F = G * giant.mass * dwarf.mass * norm(r) / mag2(r)
coeff = G * giant.mass * dwarf.mass/r.mag2()
F = r.norm() * coeff
giant.p = giant.p + F_dt
dwarf.p = dwarf.p - F_dt
giant.pos = giant.pos + (giant.p/giant.mass) * dt
dwarf.pos = dwarf.pos + (dwarf.p/dwarf.mass) * dt
print("start exec")
move()