Overview of Python & VPython

  "Welcome to VPython" tutorial

  Introductory Videos

  Pictures of 3D objects




  VPython 7 web site
  VPython license


Web VPython and


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. At webvpython.org, click "Example programs" to see how VPython is used. tinyurl.com/VPintro is an 8-minute introduction to VPython by Bruce Sherwood. No software installation is required to use Web VPython, as it runs in your browser. One can also use VPython with installed Python ("VPython 7").

This documentation is written in terms of Python syntax, because almost all Web VPython users write their programs using Python, but one can also write programs in JavaScript. This article explains how to interpret the documentation for use in JavaScript programs.

On the left is complete documentation for VPython.

Welcome to VPython, a Trinket tutorial, is useful for anyone new to programming in VPython

For a quick introduction, see the following YouTube videos, but when viewing the English-language videos be aware that for the current version of VPython the name of the module is "vpython", not "visual", and the graphics display is shown in a browser tab rather than in a bare window. (Also, for Web VPython, you can omit importing vpython.)

3D Objects (Spanish version Objetos 3D by Javier Carro)

Variable Assignment (Spanish version Asignación de Variables by Javier Carro)

Beginning Loops (Spanish version Comenzando con Bucles by Javier Carro)

Loops and Animation (Spanish version Bucles y Animación by Javier Carro)

Scale Factors (Spanish version Factores de Escala by Javier Carro)

Debugging Syntax Errors

Lists, Part 1 (Spanish verstion Listas 1 by Javier Carro)

Lists, Part 2 (Spanish verstion Listas 2 by Javier Carro)

There is a series of Web VPython tutorials by Rhett Allain in the context of predicting motion computationally, at the level of an introductory physics course. His tutorials use tools at trinket.io that embed writing and running Web VPython programs in a notebook-like environment. It is easy to use Trinkets to add both editing and execution of Web VPython to your own web pages, and Allain in his physics blog for Wired magazine has shown examples of this.

Getting started

To write a VPython program, sign in at glowscript.org. It is recommended to use the Chrome or Edge browser, as they provide the most useful error messages, though programs can be written and run in all browsers, including on smartphones and tablets. In some cases program errors are visible only if you press Shift-Ctrl-J to display the browser console.

* You will see the sentence "You are signed in as <your user name> and your programs are here." Click on here.

* Click Create New Program, which will create a new program in your MyPrograms folder. (Programs in your Private folder are not accessible to others.) Choose a name for the program, which should not include spaces or underscores.

* Below the line Web VPython 3.2, type box(). Click Run this program to run your program. You will see a white box on a black background. (An equivalent header is "GlowScript 3.2 VPython".)

* Use the right button (or CTRL-drag left button) of the mouse to rotate the camera to view the scene from different angles.

* To zoom in and out use two buttons, or ALT/OPTION-drag, or the mouse scrollwheel. Touch screen: swipe or two-finger rotate; pinch/extend to zoom.

* To pan left/right or up/down, drag the mouse with the SHIFT key held down.

Using the text editor

Here is a list of keyboard shortcuts for find, replace, etc. While editing, press Ctrl-1 (Cmd-1 on Mac) to run your program in the same window. Press Ctrl-2 (Cmd-2 on Mac) to run your program in a separate window, which lets you view your program and its execution side by side. If you change your program, press Ctrl-2 again in the editor display to re-run the program with the new changes. Web VPython uses the ACE text editor. A simpler editor is used on mobile devices.

A particularly useful shortcut is Ctrl-/ (Cmd-/ on Mac). Select one or more lines in your program and use this keypress to toggle whether those lines are commented in or out. Also, select one or more lines and press Tab to indent or Shift-Tab to unindent.

Letting others run your programs

While viewing the text of your program, 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

Introduction: The basics of Python and VPython.

A VPython tutorial: More on VPython, including making an animation

Introductory Videos: The videos listed above, easily accessible from throughout the Help

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. Key elements include these:

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

    Graphs: Making graphs of data.

    Math functions: Includes factorial/combin statistics functions

Canvases/Events: Creating/modifying windows; handling mouse/ keyboard events

Be sure to explore the many Web VPython example programs, written using Python or JavaScript. The VPython option is based on the RapydScript-NG Python-to-JavaScript compiler.

As mentioned earlier, trinket.io offers another environment for writing Web VPython programs. Click "New Trinket", then choose "GlowScript" and pick Python for normal text editing or Blocks for prompted editing.

In general, Python modules cannot be imported into Web VPython programs because they function in a JavaScript environment. However, one can import the Python "random" module into a VPython program, provided by the RapydScript-NG tool that converts Python to JavaScript. One cannot use the form "from random import *" but must use "import random" or "import random as rr" (or other name) or "from random import randint, random" (or other list of functions). Not all of the functions provided by the Python random module are available.


For those with Python and/or previous VPython experience

If you are an experienced Python programmer and/or have extensive experience with older "Classic VPython" (VPython 6 or earlier), do read this article on the differences.


Using Web VPython without an internet connection; use by developers

There is an article that explains how to use Web VPython without an internet connection, including information for how developers can use this capability.


The Architecture of Web VPython

Here is a brief overview of the Web VPython architecture. Much more extensive technical details of the Web VPython architecture are available here, which includes a video of a workshop on the topic.There is also an article that describes how pixel-level transparency and mouse picking were implemented.


Brief history

VPython was originated by David Scherer in 2000. In 2011 David Scherer and Bruce Sherwood initiated the development of Web VPython, a similar programming environment but which runs in a browser. Originally, programs had to be written in JavaScript, but in 2014 it became possible to use Python; currently Web VPython programs can be written either in Python or in JavaScript. Here is a log of major developments and here is the open source for this project. There is a blog article "A time line for VPython development". Bruce Sherwood is the lead developer.

VPython can also be used with installed Python, thanks to work originated by John Coady in 2014 and under continuing development by John Coady, Ruth Chabay, Bruce Sherwood, Steve Spicklemire, and Matt Craig. It uses Web VPython syntax but with standard Python, thereby providing access to standard Python modules. This flavor of VPython is called "VPython 7". For details see vpython.org. This documentation is valid for both Web VPython (browser-based) and for VPython 7 (installed Python).



Salvatore di Dio demonstrated in his RapydGlow experiment http://salvatore.pythonanywhere.com/RapydGlow how he was able to use the RapydScript Python-to-JavaScript compiler with Web VPython graphics. This inspired the implementation of the VPython (vpython.org) API at glowscript.org. He provided the file papercomp.js for operator overloading, based on the work of Jürg Lehni (PaperScript: http://scratchdisk.com/posts/operator-overloading. He also assembled support for operator overloading and the ability to write synchronous code in the file transform-all.js, based on the work of Bruno Jouhier (Streamline: https://github.com/Sage/streamlinejs), and Marijn Haverbeke (Acorn.js: https://github.com/marijnh). Supporting the VPython API in a browser is possible thanks to the work of Alexander Tsepkov (RapydScript: https://github.com/atsepkov/RapydScript) and Charles Law (browser-based RapydScript: https://github.com/charleslaw/RapydScript_web).

In January 2017 the original RapydScript compiler was replaced with RapydScript-NG by Kovid Goyal, which comes closer to handling true Python syntax. Goyal has been exceptionally supportive, often fixing a reported bug within just a few hours. He is also the developer of Calibre, a widely used tool for converting among ebook formats.

When the GlowScript project was launched in 2011 by David Scherer and Bruce Sherwood, Scherer implemented operator overloading and synchronous code using libraries existing at that time. In 2015 it became necessary to upgrade to newer libraries because compilation failed on some browsers; Salvatore di Dio provided crucial help in this update. In January 2017 the operator overloading machinery was further updated.


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

Russian translation by Leonid Popov

Uzbek translation by Ruslan Tarasov

Urdu translation by Sarah David

Hungarian translation by Dimitar Todorov