【发布时间】:2018-09-07 19:23:52
【问题描述】:
我希望能够停止我的模拟。我完全复制粘贴了 GlowScript 文档的代码。但是当按下暂停按钮时,它根本不会发生任何事情。唯一的事情是它将按钮中写入的内容更改为文本。我还有一个工作正常的重置按钮。暂停/运行的东西在代码的开头。我还提供了其他代码细节,因为我认为它必须对这些部分进行处理。因为我只是从 Glowscript 文档中复制的(运行/暂停的东西)
from vpython import *
running = True
def Run(b):
global running
running = not running
if running: b.text = "Pause"
else: b.text = "Run"
button(text="Pause", pos=scene.title_anchor, bind=Run)
def Reset(c):
global t, e
t=0
e.pos = vec(ae,0,0)
e.velocity = vec(0,0,-25000)
button(text ="Reset", pos=scene.title_anchor, bind=Reset)
#other constants for calc. ...
framerate = 100
#sun
s = sphere(pos = vec(0,0,0), radius = s_rad1, color=color.orange, make_trail = True )
s.mass = 2e30
s.velocity = vec(0,0,0)
#earth
e = sphere (pos = vec(ae, 0, 0), radius = e_rad, make_trail = True, color = color.blue)
e.mass = 5.9e24
e.velocity = vec(0,0,-25000)#bewegt sich mit 30000 ms
dt = 50000
time = 0.1
while (True):
rate(framerate)
g_force = g * s.mass * e.mass * (s.pos - e.pos).norm() / (s.pos - e.pos).mag2
g_forceS = -g_force
s.velocity = s.velocity + ( g_forceS / s.mass) * dt #Richtungsänderung
s.pos += s.velocity * dt
e.velocity = e.velocity + ( g_force / e.mass) * dt #Richtungsänderung
e.pos += e.velocity * dt
【问题讨论】:
标签: python simulation vpython