VPython applications for Teaching Physics

This site is being moved from http://www.phy.syr.edu/~salgado/software/vpython/
Some links may be broken... but they will be fixed.

current academic homepage: Rob Salgado (rsalgado@mtholyoke.edu)
up to: visualrelativity.com

last updated 7/30/2009 12:13PM
Since Dec 8, 2001, you are visitor number ######


  • VPython-with-the-Wiimote files mentioned at AAPT09Sum-AnnArbor.
  • Some reorganization of this page.
  • Some reogranization of URLs to other websites. (If you have a site to suggest, send me an email.)

What's Was New

  • (07/16/2008) - accelerometer example posted
    (06/20/2008) - IR-headtracking example posted
    VPython with real-time data - [Rob Salgado and Tav Hawkins]

    with the Wiimote, the Go!Motion, NeatTools-and-TNG-3B, ...

  • Most of these programs have been tested on Python 2.3.4 / VPython-Py2.3.4-2003-10-05b.exe I am trying to gradually update them to work with the newer versions. If you have made any upgrades, please share them with me.

How to run these Python programs

These python programs (pythlets?) are written in
Python with the "visual" module VPython, which provides real-time interactive visualization in 3D.

You can download the current version of VPython here and read about its development at the visualpython-users mailing list.

The older Python-2.4/VPython-3.2.9 version is here (local copy: python-2.4.1.msi and VPython-Win-Py2.4-3.2.9.exe).

Here is a local copy of the even older version (local copy: Python-2.3.4.exe and VPython-Py2.3.4-2003-10-05b.exe).


   wave_superposition.py tested with VPython23-2003-10-05

   doppler-wavefront.py tested with with Python-2.3.4.exe and VPython-2003-10-15.exe


   2D-kinematics-with-vectors.py tested with VPython23-2003-10-04
   2D-kinematics-with-vectors-circular.py tested with VPython23-2003-10-04
   2D-kinematics-with-vectors-circular-polar.py tested with VPython23-2003-10-04

1D-kinematics.py tested with VPython23-2003-09-04 1D-kinematics-with-vectors.py tested with VPython23-2003-10-04 1D-kinematics-with-vectors-alt.py tested with VPython23-2003-10-04


   EFieldBuilder-09990.py (v0.9990) tested with VPython-2003-10-05.exe
   EFieldBuilder-0997-22.py (v0.9972) requires VPython-2001-12-31.exe
   EFieldBuilder-0997.py (v0.997) requires VPython-2001-10-31.exe
   EFieldBuilder-0996.py requires VPython-2001-10-31.exe	

   Maxwell-Gauss-Coulomb_v275.py tested with Python 2.3/VPython-2003-10-05.exe 
   Maxwell-Gauss-Magnetic_v275.py tested with Python 2.3/VPython-2003-10-05.exe 

   Maxwell-Ampere.py (v2.52) tested with VPython-2001-10-31.exe
   Maxwell-Ampere_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme) 
   Maxwell-Ampere_v276.py tested with Python 2.4/VPython-3.2.9 (includes change in color scheme) 

Maxwell-Faraday.py (v2.52) tested with VPython-2001-10-31.exe Maxwell-Faraday_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme) Maxwell-Faraday_v276.py tested with Python 2.4/VPython-3.2.9 (includes change in color scheme)

   EMWave-020110.py (v0.5) tested with VPython-2001-10-31.exe
   EMWave-030216.py (v0.51) tested with VPython-2001-10-31.exe
   EMWave.py (v1.00) tested with VPython-2003-10-05.exe
   EMWave-Maxwell.py (v2.51) tested with VPython-2003-10-05.exe
   EMWave-Maxwell_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme)
   EMWave-Maxwell_v277.py tested with Python 2.5/VPython-3.2.11 (Thanks to Martin Mason for changes needed for Python 2.4+.)

Under development VPython projects (led by Rob)


Visualizing Proper Time in Special Relativity

Tensor Calculus and Differential Forms

(under development)
This demonstrates the addition of two covectors (two "1-forms") via the "co-parallelogram rule".

Aa + Ba = Ca

(2008) VPython with Real-Time Data [with Tav Hawkins]
  • (06/20/2008) VPython with real-time Wiimote data (head tracking with the IR-camera)

    tested with Python 2.4/VPython 3.2.9
    The inspiration for this project came from the efforts of Johnny Chung Lee - Projects - Wii.

    In order to read in the real-time data from the the Wiimote, we use the procedure presented by Nishio Hirokazu, which uses Brian Peek's (Windows-only) WiimoteLib v1.2.1 [a library for using a Nintendo Wii Remote (Wiimote) from .NET.] described in "Code4Fun - Managed Library for Nintendo's Wiimote (Brian Peek)". To use .NET with Python, we used Brian Lloyd's Python for .NET.

    Ideally, we would have liked to use the latest versions of the various software packages [which should be possible]. However, for now, the combination of versions that worked for us [with our program] is:

    I'm sure there is a platform-independent solution in which Python communicates directly with Bluetooth. Of course, one now needs to know details of the protocol for talking with the Wiimote.

    Note: This was just thrown together as a proof of concept. The code isn't the prettiest. The tracking and the visualization could certainly be improved.

    Some Hardware details: I bought two LED-flashlights (less than $5 each) and replaced the LEDs with IR-LEDs from DealExtreme. I mounted the flashlights onto a pair of safety goggles. (The first version is pictured here.) The Wiimote is sitting on top of my monitor, pointing toward me. [Note, I only use the Wiimote. I don't have a Wii console.]

    My current version uses IR-LEDs from Radio Shack [which seem to have a better viewing angle] and two MAGLITE Solitaire flashlights [found at Walmart] which feature replaceable LEDs. So, no soldering is needed! However, since my standard-size LEDs were too big, I had to leave off the moveable mirror/cover used to adjust the beam.

    If you don't have these IR parts available, you can try using a pair of standard (IR-based) remote controls. By the way, it's helpful to use your typical webcam or cameraphone to see the IR light to check that the LEDs are hooked-up correctly.

  • NEW! (07/15/2008) VPython with real-time Wiimote data (3-axis accelerometer)

    tested with Python 2.4/VPython 3.2.9

    After pairing your Wiimote with your computer's Bluetooth radio, your Wiimote's three-axis accelerometer readings are represented by an arrow.

    (Think of the accelerometer as "a small sphere suspended by identical springs attached to the corners of a cube".)

    When your Wiimote is sitting normally upright on your desk, it will read a_z=1. (The small sphere is displaced downwards, and the net force on the sphere due to the springs is upward.)

    When your Wiimote is in freefall (and not rotating), it will read zero. To show this, gently toss (without rotation) your Wiimote to someone. When the accelerometer value is small enough, the background color of the scene changes to white (since the corresponding small arrow is hard to see).

  • VPython with real-time Vernier Go!Motion data (ultrasonic ranger)


  • VPython with real-time data with NeatTools and Mindtel TNG-3B


VPython with the Wiimote

(based on our presentation at AAPT09Sum-AnnArbor)

(more information will be added to this section)

This is an update of our earlier version [for Python 2.4 / VPython 3.2.9 / WiimoteLib 1.2.1 / Python for .NET 1.0 ] from above.

For Windows XP and Vista... (checked with XP SP3 and Vista64)

  • Download and install Python 2.5 and VPython 3.2.11 (You can also try Python 2.6 and Visual 5. I haven't tried "Python 2.5 with Visual 5".)

  • To get data from the Wiimote, you need Brian Peek's WiimoteLib library using .NET (which is the library used for Johnny Chung Lee's Wiimote projects, as well as many others).
    The latest stable version is WiimoteLib 1.7.
    (Alternatively, for partial support of the Wii MotionPlus extension, try WiimoteLib 1.8 beta.)

    The only file you need from the downloaded package is WiimoteLib.dll.
    (It is helpful to also use WiimoteTest.exe to see all sorts of data from the wiimote.
    You'll find documentation for the library, WiimoteLib.chm, in the docs/ folder. )

  • To get Python to talk to WiimoteLib, you need Python for .NET 2.0, which provides clr, an interface to the .NET Common Language Runtime.
    Unfortunately, the file pythonnet-2.0-alpha2.zip only works for Python 2.4.

    Fortunately, Feihong Hsu figured out that one can compile the Python for .NET source code and tweak switches to make it work in Python 2.5 and in Python 2.6. In the end, all you need are the two files Python.Runtime.dll and clr.pyd placed in the Python folder (e.g. C:\Python25 ).

  • (I'm travelling right now... I'll continue later this weekend with some example programs.)

  • In summary:
    • In your Python installation folder, Python.Runtime.dll and clr.pyd.
    • In the folder with your Python program, WiimoteLib.dll.
[more to come!]

VPython applications (up)
Programming Notes
Using Python 2.3

Here's a registration-file for Windows 2000 and Windows XP that will fix that problem with the IDLE editor closing completely when terminating an animation you are working on. Python-File-new.reg It assumes that you installed Python in the C:\ drive. If so, you may just "Open" it. Otherwise, download [Right-click->Save Link to...] the appropriate pair to your desktop, then after reading the .reg files and making any desired changes, merge with your registry. Then, "Merge" it by double-clicking on it.


If you mess up, you can try to clean things up in Explorer via Tools->FolderOptions->FileTypes...->PY Python File->Advanced
..or else use regedit.
Use at your own risk! (Backup your registry before merging!)

Using Python 2.3 and Python 2.4

These registry hacks to allowed me to select which VPython version is used to execute a .py file. They may work for you.
Use at your own risk! (Backup your registry before merging!)
Download [Right-click->Save Link to...] the appropriate pair to your desktop, then after reading the .reg files and making any desired changes, merge with your registry.

My Python installations are on the F:\ drive:

Py23_HLM_driveF.reg - Py24_HLM_driveF.reg

If your installations are on the C:\ drive, use:

Py23_HLM_driveC.reg - Py24_HLM_driveC.reg

If you mess up, you can try to clean things up in Explorer via Tools->FolderOptions->FileTypes...->PY Python File->Advanced
..or else use regedit.
Use at your own risk! (Backup your registry before merging!)

This program demonstrates a subtlety in the copyobjects() function on http://www.vpython.org/webdoc/visual/options.html
copyobjects-subtlety.py tested with VPython23-2003-09-18

Working example of an improved copyobjects() and a new updatecopyobjects().
copyobjects-example.py tested with VPython23-2003-09-18

related sites:

VRML Gallery of Electromagnetism
The Light Cone

other VPython sites I have found

Got a site to suggest? (salgado@physics.syr.edu)

Google search for "from visual import"
AlltheWeb search for "from visual import"
MSN search for "from visual import"
Yahoo search for "from visual import"


Python Programming Language -- Official Website


Rob Salgado (Syracuse)
VPython projects at Dillard University (Salgado)
Matter & Interactions (Ruth Chabay and Bruce Sherwood, NCSU)
Matter & Interactions (Ruth Chabay and Bruce Sherwood, NCSU) [Wiley]
Vpython - AIMSWiki
VPython: 3D Interactive Scientific Graphics for Students (CISE)
Python Notes

Python Programming

Non-Programmers Tutorial For Python
Learning to program
Dive into Python
Python DevCenter
ASPN Cookbook
Beazley's Python Slides (javascripted)
Python Tutorials
Python Short Course
Numerical Python
Numeric Python Tutorial
Minimal Python for Scientific Computing
Handbook of the Physics Computing Course (Python language)
Handbook of the Physics Computing Course (Python language)
An Incremental Introduction to Python (Noack) - large pdf
Python Patterns - An Optimization Anecdote
Teaching with Python
Python Performance Tips
many Python links
pygsear ~~: Pygame Framework and Examples
PythonD 32bit Python for DOS and Windows
Explorer's Post 631 Learning Ideas
Python Eggs
Jython3D : Python and Java 3D
Movable Python - The Portable Programming Environment


Computational Biophysics (Drexel)
Computational Physics and the Open Source Physics Project (Gould, Clark U)
PHY 307/607 Codes
Konrad Hinsen's Python Page
Programming for Physical Sciences (Physics, Computer, Computing)
ScientificPython (Konrad Hinsen)
Tutorial in Computational Science using Visual Python (ANU)
Simulating a Gas (ANU)
Using Visual Python to Simulate a Bouncing Ball (ANU)
Introducción a la computación
UCT Physics PHY400W - Computational Physics
PythonD 32bit Python for DOS and Windows


VPNBody Symplectic Integration Package for VPython


Physics 271 - Electricity and Magnetism (Sergei Savikhin, Purdue)
Brendan Kiburg (UIUC)


KineticsKit (Markus Gritsch)
Classical Mechanics (Eduardo Velasco - Truman State)
Coriolis effect (Peter Bowyer)
Theoretical Mechanics (Schneider, Lawrence Technological University)
Physics241 Labs
Schedule 2004
404 Not Found
Theoretical Mechanics (Scott Schneider, Lawrence Technological University)
UCT Physics PHY110W - Python


3d Earth Science Models (Lensyl Urbano - U Memphis)
Main Page - GeoMod


A Mathematical Canvas (Kirby Urner)
Lorentz Attractor (Kirby Urner)
3D PyArt (Stephen Vashaw)
PyGeo (Arthur Siegel)


Visualizing Proper Time in Special Relativity [with LightClocks] (Rob Salgado)


Larry Martin (NorthPark)
UCT Physics PHY321F
Andrew Dougherty's Python Page
Index of /~doughera/phys218-2003/vpython
Udell Blogroll exploration
CodesVpython - Wiki Python Fr
Highland's VPython programs


PHYS 3821 Wave function simulator (Brian Quirt)
Herbert Looser (University of Applied Sciences, Aargau)
Object not found!
PyARX (Hoper)
The page cannot be found
Modern Physics Laboratory Software (Carnegie Mellon)
VPython - Animations (Horn, Dortmund)
an hourglass timer (Timothy M. Brauch)
PHY107 General Physics (David Snyder, Gallaudet )
Testing the Law of Gravity with Satellites (Jennifer Buckman, PHY 107 student at Gallaudet)
zwiki: MadCUPViewer