|
This is documentation for Classic VPython (VPython 6), which continues to be available but is no longer supported. See vpython.org for information on installing VPython 7 or using GlowScript VPython. Documentation is available at glowscript.org by clicking Help. Here is a complete VPython program that produces a 3D animation of a red ball bouncing on a blue floor as shown above. Note that in the "while" loop there are no graphics commands, just computations to update the position of the ball and check whether it hits the floor. The 3D animation is a side effect of these computations. from visual import
* The program starts by importing the module "visual" which enables 3D graphics. A box and a sphere are created and given names "floor" and "ball" so one can refer to these objects. The ball is given a vector velocity. In the while loop, "rate(100" has the effect "no more than 100 loops per second on fast computers." The ball's velocity is used to update its position, in a single vector statement that updates x, y, and z. Visual periodically use the current values of the objects' attributes, including ball.pos, to paint a 3D picture. The program checks for the ball touching the floor and if necessary reverses the y-component of velocity, otherwise the velocity is updated due to the gravitational force.
|
|||||