Using VPython in the Physics Computer Cluster

Use "IDLE for VPython"

"IDLE for VPython" is a programmer's editor that comes with Python and VPython. Although you can use any text editor (like Notepad), IDLE knows about Python and can be very helpful in debugging and executing your programs.


Try one of the simplest VPython programs.

from visual import *

floor = box (pos=(0,0,0), length=4, height=0.5, width=4, color=color.blue)
ball = sphere (pos=(0,4,0), radius=1, color=color.red)
ball.velocity = vector(0,-1,0)
dt = 0.01

while 1:
	rate (100)
	ball.pos = ball.pos + ball.velocity*dt
	if ball.y < ball.radius:
		ball.velocity.y = -ball.velocity.y
	else:
		ball.velocity.y = ball.velocity.y - 9.8*dt
The indentation is important. It tells Python which are logical-blocks of code. In some other languages (like C++ or Java), one would have used braces { } to enclose these blocks of code.

The first line

from visual import *

tells the Python program to use the VPython library, which is very physics-friendly graphics library. More information about VPython is available from links at the bottom of this page.


My fix for an annoying IDLE problem

When interrupting a running VPython animation by killing the window (clicking on the [X} in the upper right hand corner of the window), the entire IDLE editor shuts down... in the default installation!

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.

Python24-File-new.reg for the SU installation of VPython.

It assumes that you installed Python in the C:\ drive.
If so, you may just "Open" it.
Otherwise, you must "Save" it, then edit it if you installed it elsewhere.
Then, "Merge" it by double-clicking on it.


More information...


more later...


Rob Salgado

back