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 — Home work 2 — Weeks 12 and 13

More Visual Python (VPython)

IMPORTANT

Home works are unsupervised — so no tutor will be in the lab room in weeks 11 and 12.

We like to encourage you to post questions to the comp2720.talk discussion board, which we will check regularly (and answer your questions).

Objectives

The objectives of this 2nd home work are to become more familiar with Visual Python programming, including building composite objects, animate them and react to keyboard inputs.

Marks and submission

  • You will not get any marks (directly) for this home work, which means you don't have to show it to your tutor in the labs.

  • However, your will get marks for including your home work into your portfolio (see the portfolio page for more details).

  • Please do NOT e-mail your home work to your tutor — we will NOT mark e-mailed home works.

  • Please do NOT e-mail us questions regarding your home work - use the comp2720.talk discussion board instead.

Preliminaries

 

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

  2. Download the lab-template.txt and save it in your hw2 folder under the name hw-2-diary.txt.
    Please only save your home work 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 hw-2-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 hw2 folder:
    • From the COMP2720 lecture slides Web page the Visual Python program: bounce2.py (the same program as used in lab 6).


Part 1: Creating a compound object and animate it

  1. In this part you should create a compound Visual Python object that is made of at least five (5) simple objects (like sphere(), cylinder(), etc.), for example a human figure or animal with a body, head, arms and legs, or a biological molecule, or a space ship, a car, whatever. You should combine all these objects into one by creating a compound object using frame().

  2. Once you are happy with your object copy it into the original bounce2.py program. Remove the bouncing ball from the program and insert your object, and then modify the code so that your object is bouncing around.

  3. You might have to make the box larger if your object is larger (or almost as large) as the box. If you like you can also change the shape and colours of the box.

  4. You will also have to modify the test conditions that make the object bounce back from the walls of the box, so that your compound does correctly bounce back from the walls, and not inside or outside the box.

  5. Now add some code to your program that makes your object rotate slowly in one direction (around one axis) while it bounces around.

  6. Once it works save your program as bounceObject.py, and describe what you have done into your home work diary. Remember you will have to include your home work into your portfolio (both program codes and the home work diary).

Part 2: Modify rotational speed via keyboard input

  1. In this part you should add keyboard control for the rotational speed of your object as follows:

    • Pressing f should make the rotation faster.
    • Pressing s should make the rotation slower.

  2. Your program should print a message into the output (terminal) window each time a key is pressed: if the f or s key has been pressed, and the old and new rotational speed (the initial value is up to you, as chosen in part 1 of the home work).

  3. Once it works save your program as bounceObjectKey.py, and describe what you have done into your home work diary. Remember you will have to include your home work into your portfolio!


Further programming ideas

In each home work 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 provides some more problems for students who love a programming 'challenge'.

  1. Add keyboard control for changing the direction of the rotation, for example typing keys x, y or z would set the direction (axis) of the rotation.

  2. Modify your program so the bouncing slows down according to physical laws (i.e. the speed of the bouncing becomes slower and slower, and at the end your object stops moving - and is ending up on the floor of the box).


Last modified: 5/08/2008, 00:09