---
# System prepended metadata

title: VPython
tags: [VPython, Python]

---

# VPython

###### tags: `Python`, `VPython`

VPython is the Python programming language plus a 3D graphics module called Visual. VPython is a programming language that is easy to learn and is well suited to creating 3D interactive models of physical systems. 

## The Canvas

When using VPython the canvas shows objects in 3D.

(0,0,0) is in the center of the canvasaxes . The +x axis runs to the right, the +y axis runs up, and the +z axis points out of the screen, toward you.

x, y, and z are measured in whatever units you choose; the canvas is automatically scaled appropriately.

![](https://i.imgur.com/iLN7BYP.png)

## The Output window

The output of any `print` statements you execute in your program goes to a scrolling text window underneath the graphics window. You can use this window to print values of variables, print lists, print messages, etc.

## The Code window

If you type or copy the following simple program into the program editor and run it, you will see a canvas conatining a red box and a green sphere.

```Python
redbox=box(pos=vector(4,2,3),
           size=vector(8,4,6),color=color.red)
ball=sphere(pos=vector(4,7,3),radius=2,color=color.green)
```

## Viewing the Scene

In the canvas, click and drag with `right mouse button` (or hold down `Ctrl` while dragging). Drag left or right, and you rotate around the scene.

To rotate around a horizontal axis, drag up or down. Click and drag up or down with `middle mouse button` to move closer to the scene or farther away (on a 2-button mouse, hold down `left and right mouse buttons`; on a 1-button mouse, hold down `Alt`). 

To pan left/right and up/down, drag with `shift` held down.

## Reference

[Complete Documentation for VPython](https://www.glowscript.org/docs/VPythonDocs/index.html)