If you're new to Python
A VPython tutorial
Pictures of 3D objects
Using VPython to create 3D animations
VPython makes it unusually easy to write programs that generate navigable real-time 3D animations. It is based on the Python programming language which is widely used in introductory programming courses thanks to its clean design, and it is also widely used in science and business.
Classic VPython was originated by David Scherer in 2000. In 2011 David Scherer and Bruce Sherwood initiated the development of GlowScript, a similar programming environment but which runs in a browser. In 2014 it became possible to use RapydScript, a programming language very similar to Python, to support VPython programs in the GlowScript environment.
There is also a "Jupyter VPython" originated by John Coady in 2014 and under continuing development by John Coady, Ruth Chabay, Bruce Sherwood, Steve Spicklemire, and Matt Craig. It runs in a Jupyter notebook and uses GlowScript VPython syntax with standard Python, thereby providing access to standard Python modules. For details see vpython.org. Also of interest is a discussion about plans for the future evolution of VPython.
This documentation describes both the GlowScript and Jupyter versions of VPython.
For a quick introduction, see the following YouTube videos. These were created for Classic VPython but are just as useful for learning the more recent versions.
There is a series of GlowScript VPython tutorials by Rhett Allain in the context of predicting motion computationally, at the level of an introductory physics course.
To write a VPython program, sign in at glowscript.org.
See the start of the technical documentation for details about how to use the text editor to search, replace, etc. Note that you can press ctrl-1 to run your program instead of clicking "Run this program". Or press ctrl-2 to run your program in a separate window, which lets you view your program and its execution side by side. After making a change to your program press ctrl-2 to see the effect of your changes; it isn't necessary to close the execution window.
It is recommended to use the Chrome browser for developing programs, as it provides the most useful error messages, though programs can be written and run in all browsers, including on smartphones and tablets.
Letting others run your programs
On the GlowScript edit page, click Share this program to see how to let other people run your program. For people to run your program by linking to it, the program must be in a public folder or be exported to your own web site. In fact, the code available on the share page can simply be pasted into a file and saved with the extension ".html", and then you can run the program simply by doubleclicking the html file.
Descriptions of the options available in the left margin
For experienced programmers
As a convenience to novice programmers to provide everything that is needed to get started, GlowScript 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.
You can however import selectively, as shown in the following examples, which are compatible with Jupyter VPython. (To help with converting from Classic VPython, you can refer to "vis" or "visual" instead of "vpython".)
For those who have used Classic VPython
A few Classic VPython objects are not currently available in GlowScript: convex, faces, and frame. The GlowScript objects vertex, triangle, and quad represent a more powerful alternative to faces. Many applications of frame can be handled with the GlowScript compound object.
One way to deal with differences is to check the elements of the "version" variable that is available in both Classic VPython and the GlowScript version and do different things in the different environments:
Classic VPython: version is ['X.Y', 'release']
The curve and points objects are somewhat different in the GlowScript environment, but with a little care it is possible to use these objects in such a way that they will also work in Classic VPython. Note that in GlowScript 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 both in Classic VPython 6 and in GlowScript. Also available are scene.pause() and scene.waitfor('click') and related options.
GlowScript 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
GlowScript 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 GlowScript or Jupyter 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 GlowScript 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.
In the GlowScript environment pos, size, axis, color, and up are all vectors, and they are somewhat special vectors that track changes in order to trigger correct rendering of the 3D scene when one of these object attributes changes. One result of this architecture is that
In GlowScript and Jupyter you can use the shorthand "vec" for "vector". If you wish to use a GlowScript program containing "vec" in the Classic VPython environment, just add the statement "vec = vector" at the start of the program.
Salvatore di Dio demonstrated in his RapydGlow experiment
In January 2017 the original RapydScript compiler was replaced with RapydScript-NG by Kovid Goyal, which comes closer to handling true Python syntax.
When the GlowScript project was launched in 2011 by David Scherer and Bruce Sherwood,