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)

 
VPython

Classic VPython 6.11
based on wxPython

materialetc

This is documentation for Classic VPython (VPython 6), which is no longer supported but is provided here as historical material. See vpython.org for information on installing the vpython module or using Web VPython. Documentation is available at webvpython.org by clicking Help. 

 

Changes from VPython 5

VPython 6 will run almost all old VPython programs correctly without change The following details about changes may be important in a few unusual cases.

An animation loop must contain a rate or sleep statement, which limits the number of loop iterations per second as before but also when appropriate (about 30 times per second) updates the 3D scene and handles mouse and keyboard events. Without a rate or sleep statement, the scene will not be updated until and unless the loop is completed. Most animation loops already contain a rate statement anyway, to make the animation not run too fast.

You should use the new function sleep rather than time.sleep. The new function periodically renders the scene and processes mouse events, making it possible to continue using zoom and rotate, whereas time.sleep 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.

You must import visual or vis before importing graph or controls or filedialog, which most users have always done anyway.

Be sure to read what's new in the latest version of VPython 6.

Rotate and zoom

To rotate the camera around the scene, drag with the right button down, or with the Ctrl key down. To zoom in or out, drag with both the left and right buttons down or with the Alt key down (also called Option on the Macintosh).

How to learn about VPython

VPython is the Python programming language plus a 3D graphics module called "Visual" originated by David Scherer in 2000. This documentation describes all of the VPython capabilities.

For a quick introduction, see these YouTube videos:

3D Objects

Variable Assignment

Beginning Loops

Loops and Animation

Scale Factors

Debugging Syntax Errors

Lists, Part 1

Lists, Part 2

Descriptions of the options available in the left margin:

Introduction: The basics of Python and VPython.

Tutorial: More on VPython, including making an animation

Pictures of 3D objects: What the objects look like

Choose a 3D object: Details of cylinder, box, etc. Start with cylinder for an overview.

Work with 3D objects: Issues that apply to all 3D objects: color, material, etc.

Windows, Events, & Files: Creating/modifying windows; handling mouse/ keyboard events; reading/writing files

Vector operations: Magnitude, dot and cross product, rotation, etc.

Graphs: Making graphs of data.

factorial/combin: Special functions used in probability calculations.

What's new: Features new in VPython 5.

Be sure to explore the many example programs that are installed with VPython.

GlowScript: GlowScript (glowscript.org) now supports VPython, which allows VPython programs to run in a browser. See the Help and VPython Help at glowscript.org.

iPython: John Coady has implemented VPython to run in iPython notebooks, with his ivisual module.

 

To invoke the Visual module, place the following statement at the start of the file:

from visual import *

If you are using Python 2.7 or earlier, to make sure that 3/4 is treated as 0.75 rather than zero, start your program with the following statements (there are two underlines before future and two underlines after future):

from __future__ import division
from visual import *

This is not necessary with Python 3.0 or later, but it doesn't hurt, and including the division statement ensures that your program will handle division the same way on all versions of Python.

For experienced programmers

As a convenience to novice programmers to provide everything that is needed to get started, the statement "from visual import *" imports all of the VPython features and executes "from math import *" and "from numpy import *". It also arranges that for routines common to both math and numpy such as sqrt, the much faster math routine is used when possible (when the argument is a scalar rather than an array).

If you want to import the VPython objects selectively, import them from the vis module. Two simple examples:

import vis
vis.box(color=vis.color.orange,material=vis.materials.wood)

 

from vis import (box, color, materials)
box(color=color.orange, material=materials.wood)

There are clean modules vis.controls, vis.filedialog, and vis.graph equivalent to the modules visual.controls, visual.filedialog, and visual.graph.

The documentation is written assuming that "from visual import *" is used.

VPython documentation was produced by Ruth Chabay, David Scherer, and Bruce Sherwood.