Home

If you're new to Python
and VPython: Introduction

A VPython tutorial

Pictures of 3D objects

What's new in VPython 6

VPython web site
VPython license
Python web site
Math module (sqrt etc.)
Numpy module (arrays)

 

Limiting the Animation Rate

rate( frequency )

Halts computations until 1.0/frequency seconds after the previous call to rate().

For example, rate(50) will halt computations long enough to make sure that at least 1.0/50.0 = 0.02 second has elapsed. If this much time has already elapsed, no halt is performed. If you place rate(50) inside a computational loop, the loop will execute at a maximum of 50 times per second, even if the computer can run faster than this. This makes animations look about the same on computers of different speeds, as long as the computers are capable of carrying out 50 computations per second.

As of VPython 6, it is obligatory to place a rate statement in an animation loop. Without it, no screen updates or processing of mouse or keyboard events are possible.

Another option is to use the new VPython function sleep: sleep(0.02) means "don't do anything for 0.02 seconds" and is equivalent to rate(50). The sleep function periodically renders the scene and processes mouse events, making it possible to continue using zoom and rotate, whereas the standard Python function time.sleep(t) does not do this. Programs that use time.sleep will work, but you won't be able to zoom or rotate during the sleep period.