Difference between revisions of "CSC111 Homework 8"

From dftwiki3
Jump to: navigation, search
(Problem #2: Optional and Extra Credits)
(Problem #2: Optional and Extra Credits)
Line 55: Line 55:
 
</bluebox>
 
</bluebox>
  
<center>[[File:UnderConstruction.jpg | 150px]]</center>
+
<center>[[File:UnderConstruction.jpg | 150px | Under Construction]]</center>
  
 
<br />
 
<br />

Revision as of 07:10, 25 March 2010

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 graphics 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 too big so as to make the balls "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, "111c-xx 111c-yy" )

Realism

  • It is not easy nor possible with our current knowledge of Python to make the bouncing of the balls off each other realistic. When a ball hits a wall, the rule is very nice and clear: we change the sign of either dx or dy, depending on which is perpendicular to the wall. When the balls hit each other, both dx and dy would normally change. The real equation for how dx and dy change is too complicated for us. Invent your own laws of physics and implement them in python!

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 ):
     """Computes the distance between Point P1 and Point P2.  The returned value is a float"""
     return sqrt( pow( P1.getX() - P2.getX(), 2 ) + pow( P1.getY() - P2.getY() ) )

Problem #2: Optional and Extra Credits

Will be provided later on Thursday...

Under Construction