CSC111 Homework 8

From dftwiki3
Revision as of 19:17, 24 March 2010 by Thiebaut (talk | contribs) (Submission)
Jump to: navigation, search
This homework assignment is due on April Fool's Day, 4/1/10, at midnight



Problem #1

Statement

Write a program that moves two balls on the screen, in fashion similar to what you did in Lab 8, with the following twists:

  1. the two balls should bounce off the walls (border of the graphics window)
  2. the two balls should bounce off each other.
  3. there should be three black boxes in the graphics window, and if any one of the two balls happens to move completely inside any one of the boxes, it should stop there.
  4. the program should stop and display click to End" when the simulation has gone through 300 steps, or as soon as the two balls have been immobilized in boxes.
  5. there should be a fourth box, this one white, which should act as an obstacle. Any time a ball hits the white box, it should bounce off the walls of the box, in a same way it bounces off the walls.

Requirements

  • Use boolean functions
  • Use a list to hold the black boxes.
  • You are free to select the size of the white and black boxes, but make them big enough to allow balls to hit them regularly, but not to big so as to make the ball "fall" in a black box before having time to hit a few walls or the white box.
  • Include your account name(s) or your first name(s) in the title of the graphics window to make it easier to identify printed screen captures of your running program:
      win = GraphWin( W, H, "231c-xx 231c-yy" )

Submission

  • Submit your program as follows:
   submit hw8 hw8a.py

Additional Information

  • You may find the following function useful for computing the distance between two graphics points:
from math import *   # this should be at the beginning of the program

def distance( P1, P2 ):
     return sqrt( pow( P1.getX() - P2.getX(), 2 ) + pow( P1.getY() - P2.getY() ) )