CSC111 Homework 8
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:
- the two balls should bounce off the walls (border of the graphics window)
- the two balls should bounce off each other.
- 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.
- 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.
- 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() ) )