首页 > 解决方案 > VPython 上的数组中的延迟信息

问题描述

我正在做一个项目,我将角度值临时存储到一个数组中,在视觉模拟中使用它们,然后在显示更新后删除这些值。

我正在尝试创建相同值的相同数组,但是我希望它们延迟一定的量(我希望该量是可变的)。我该怎么做呢?我已经考虑在开始时对数组进行零填充,但是 numpy 零填充不允许附加值。

标签: pythonarraysfunctiondelayvpython

解决方案


您可以在 vpython 程序中使用 % modulo 运算符作为变量延迟。在 vpython 程序中,您通常有一个以给定帧速率永远运行的模拟循环。

delay = 30     # configurable delay
cnt = 0
while True:
    rate(30)   # vpython simulation runs at 30 frames per second (fps)
    cnt += 1
    if cnt % delay == 0:      # delay one second  (delay/30fps = 1 second)
        # do what you want with your array when the delay time has been reached.
    else:
        # do something else

约翰


推荐阅读