Overview of Python & VPython

  "Welcome to VPython" tutorial

  Introductory Videos

  Pictures of 3D objects




  VPython 7 web site
  VPython license

For those with Python and/or previous VPython experience

As a convenience to novice programmers to provide everything that is needed to get started, VPython by default imports all of the VPython features and includes standard math functions such as sqrt. The documentation is written as though "from vpython import *" were present. Also provided are clock(), random(), and arange(), and range() is like arange(); it accepts floating-point arguments.

You can however import selectively, as shown in the following examples, which are compatible with VPython 7. (To help with converting from Classic VPython, VPython 6, you can refer to "vis" or "visual" instead of "vpython".)

import vpython
import vpython as vp # "vp" is any name of your choice
from vpython import box, color

When using the form "from vpython import .....", if canvas is not specified, it is added, as Web VPython cannot run without canvas.


For those who have used Classic VPython

A few Classic VPython objects are not currently available in VPython: convex, faces, and frame. The objects vertex, triangle, and quad represent a more powerful alternative to faces. Many applications of frame can be handled with the compound object.

One way to deal with differences is to check the elements of the "version" variable that is available in all versions of VPython:

Classic VPython:    version is ['X.Y', 'release']
Web VPython: version is ['X.Y', 'glowscript']
VPython 7:          version is ['X.Y.Z', 'jupyter']
   and in VPython 7, the version of the Web VPython graphics library
   is given by GSversion as ['X.Y', 'glowscript']

The curve and points objects are somewhat different from Classic VPython. Note that now the list of points in a curve object is not a numpy array, so that a loop is required to change all of the points.

To handle mouse events one cannot use scene.getevent() but must use scene.bind(), which is available in all versions of VPython, starting with Classic VPython 6. Also available are scene.pause() and scene.waitfor('click') and related options.

In Web VPython it is not possible to import arbitrary Python modules such as numpy, and any program that uses numpy will have to be modifed. However, loops are fast in the JavaScript language to which Web VPython programs compile, so if you are using numpy solely for the speed of array manipulation, you may be able to replace a numpy calculation easily and efficiently with a loop.

Web VPython by default processes VPython programs as though they had the following statements at the start of the program (which you don't need to include; they will be ignored):

from __future__ import division, print_function
from vpython import *

Web VPython treats 3/2 as 1.5 as in Python 3.x, not 1 as in the Python 2.x language, and the print statement must take the Python 3.x form of print('hello') rather than the Python 2.x form of print 'hello'.

Many programs written in Classic VPython 6 will run in Web VPython or VPython 7 without change after being run through a conversion program written in Python. This program converts (x,y,z) => vector(x,y,z) and obj.x => obj.pos.x. These changes are necessary because Web VPython does not recognize (x,y,z) as a vector nor obj.x as a shorthand for obj.pos.x. The program also converts display => canvas and gdisplay => graph. The program also converts scene.mouse.getclick() => scene.waitfor('click'), which works in both environments.

In Web VPython and VPython 7 you can use the shorthand "vec" for "vector". If you wish to use a Web VPython program containing "vec" in the Classic VPython environment, just add the statement "vec = vector" at the start of the program.