Having 3D fun with Visual Python

Visual Python or vpython is python library for simple 3D animation, especially useful for animation of  simple physical scenes – like pendulum, ball on a spring, movement in gravitational field etc.  It is fairly simple to use and gives quite nice animations, which can demonstrate some  laws of physics.  I actually spot this package, when I saw an article about physics in popular mobile game “Angry Birds – Space”. In that article they had been arguing about physics laws in the game and also referred to  vpython, where they made some experiments. I told myself I have to try it myself, so I’ve created small program using vpython.

The program is here and simulates movement of a ball within gravitational field of a planet, where also atmosphere friction is present . Below is a video from program run:


Install Visual Python

Although there is package python-visual in Ubuntu repositories, this package is  fairly ancient and is missing latest features – like tracking of movement etc. So if you want to have most of vpython you should install latest version from sources, however process is not completely straight forward (as authors themselves admit), so I’m recording here for reference my steps(On linux Mint 13/ Ubuntu 12.04):

  1. Download source from http://www.vpython.org/contents/download_linux.html
  2. Unpack
  3. Install dependencies – libraries:
    sudo apt-get install automake libgtkmm-2.4-dev libglademm-2.4-dev libgtkglextmm-x11-1.2-dev  libboost-dev libboost-python-dev libboost-thread-dev libboost-signals-dev
  4. Install also some depended python packages that are not in repository:
    1.  FontTools – should be installed manually, easy_install does not find them
      download from http://sourceforge.net/projects/fonttools/files/latest/download
      unpack and install – sudo python setup.py install
    2. ttfquery – sudo easy_install ttfquery
    3. Polygon –  again manually, because easy_install get version for python 3.
      download from https://github.com/jraedler/Polygon2/zipball/master
      unpack and install – sudo python setup.py install
  5. In vpython directory run:
    sudo make install
  6. However install scripts installs package to /usr/local/lib/python2.7/site-packages,  which is not on python path by default, so we have move them (or modify python path):
    sudo mv /usr/local/lib/python2.7/site-packages/vis  /usr/local/lib/python2.7/dist-packages/
    sudo mv /usr/local/lib/python2.7/site-packages/visual/  /usr/local/lib/python2.7/dist-packages/
  7. Run python, try import visual to see that all works

Leave a Reply

Your email address will not be published. Required fields are marked *