CECS Home | ANU Home | Search ANU
The Australian National University
ANU College of Engineering and Computer Science
School of Computer Science
Printer Friendly Version of this Document

UniSAFE

COMP2720 — Lab 6 — Week 11 (16th and 17th October 2008)

Visual Python (VPython)

IMPORTANT

You should be familiar with the basics of Visual Python by having looked at the slides from lecture VPython-1 and the simple example program bounce.py, and having read the Tutorial Introduction on the VPython Web site.

Objectives

Create simple 3D animations using Visual Python.

Marks and submission

  • You will get one mark if you attend this lab, and another mark when you show and demonstrate your working to your tutor.

  • Note that we will not give you an attendance mark if you only come to the lab for a short while.

  • The mark for your lab workings will only be awarded in the lab. You can show your workings only in this lab (as this is the last lab). You will not receive a mark for this lab if you show it to your tutor after the lab, unless you have a medical certificate (or similar document) stating that you were unable to attend the normal lab.

  • Please do NOT e-mail your lab workings to your tutor — we will NOT mark e-mailed lab workings. You can only get the mark for workings in the labs.

IMPORTANT

Note that this lab is the LAST OPPORTUNITY for you to show (and get marks for) any lab workings. We will not consider any lab workings after lab 6 (unless you have a medical certificate (or similar document) stating that you were unable to attend the normal lab).

The workload in this lab is smaller that in previous labs, which should allow you to catch up and finish your previous lab workings.

Preliminaries

  1. Once logged onto a computer, create a sub-folder called lab6 in your folder comp2720.

  2. Download the lab-template.txt and save it in your lab6 folder under the name lab-6-diary.txt.
    Please only save your lab diary as simple text file, not in RTF or DOC format (as you will have to include your lab diaries into your portfolio, and we will not be looking at RTF or DOC files when assessing your portfolio).

  3. Open this file lab-6-diary.txt with a text editor, and complete the header with your details. Keep this file open and continue writing down your workings and paste your programs into it.

  4. Now copy the following file into your lab6 folder:

  5. Running VPython on Linux:

    1. Start the Konsole (aka terminal) application, by selecting it from the Application → System Tools → Konsole on KDE front panel menu at the bottom. (For future ease of opening the Konsole, you can add its icon to the front panel by double-clicking on the the front panel bar, selecting "Add to Panel...", then choosing "Application Launcher...", the scrolling down to "System Tools" tree node, opening it, and selecting "Konsole" icon and pressing "Add" button.)

    2. In the Terminal window, type in the command:
      u1234567% idle &
           
      which will open the IDLE shell, which will look similar to this:

      Instead of IDLE one can use any text editor, like Kate. In this case you do not have access to the package/class browser, and you cannot run the scripts by simply pressing "F5", but the documentation on any available Python package can be accessed by typing on the command-line (in Terminal window):

           pydoc package_name
           
      and the VPython scripts can be run on the command-line, like any other Python scripts (see below)

    3. In the IDLE shell, type in the following commands:
      >>> import sys
      >>> sys.path.append('/sw/lib/python2.3/site-packages/visual')
      >>> from visual import *
      >>> sphere()  # Quick test
                
      A window with the white sphere displayed will open (a scene in VPython). You can change and add to the displayed "stuff" by typing VPython commands in the IDLE shell (see examples in the lecture notes, and in the VPython on-line tutorials and documentations).

    4. You can load a Python program using File.. and then Open. A new window containing the program will open.

    5. You can use F5 (in the program window) to start (run) a program (or see the Run menu).

    6. Once you close the scene window, the from visual import * declaration is gone, and has to be retyped again if you want to continue. This is awkward (but not my fault). The IDLE shell also has no history mechanism (the one you've got accustomed to while using the JES's command area). Therefore, you can alternatively run VPython programs, by calling the Python interpreter on the command-line ( in Terminal window) as follows:
      u1234567% cd ~/comp2720/labs/lab6
      u1234567% python bounce.py
                
      and edit your VPython scripts by using an ordinary plain text (as suggested above) editor.


Part 1: More bouncing objects

You should spend around 70 minutes on this part of the lab.

  1. Open the program bounce2.py into your favourite text editor (NOT into JES!). Read the program and try to understand it, then run it with VPython. See the Tutorial Introduction on the VPython Web site which explains parts of this program in more details.

  2. Now add a yellow box to the program, with dimensions (1, 1/3, 2/3), and a starting position different from the green ball. The mass of the box should be 2, and it's initial direction of movement should be different from the green ball's movement.

  3. Re-run your program and debug it until the yellow box is also correctly reflected (i.e. bouncing back) by all walls.

  4. Now make the yellow box rotate slowly while moving around. Set the rotation rate to around half a full turn every second.

  5. Finally, add a purple ellipsoid with dimensions (1,2,3) which rotates twice per second around its shortest dimension and also bounces around in the box.

Part 2: Show your workings to your tutor

You should spend around 10 minutes on this part of the lab.

  • Explain and show to your tutor what you have done in part 1 of the lab, show the resulting 3D animation created, and the programs you have developed.

  • Please also show your tutor your lab diary.


Further programming ideas

In each lab we will provide a last section that contains ideas for people who want to dig deeper, who are hooked on Python or media programming. This section is not part of the assessable lab material, but rather provides some more problems for students who love a programming 'challenge'.

  1. Design a figure made of a head, body, arms and legs, using different objects and the frame capabilities in VPython (which allows you to 'glue' together different objects into one), and make it bounce around the box.

  2. You might also want to try and add rotation in all thee dimensions to the bouncing figure.

  3. Finally, try to add collision detection between the walls of the box and your figure!


Last modified: 5/08/2008, 13:14