CSC111 Homework 8

From dftwiki3
Revision as of 15:53, 25 March 2010 by Thiebaut (talk | contribs) (Problem #2: Optional and Extra Credits)
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 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
Under Construction...
  • Your assignment is to write a program that will read a long string of characters which represents the results of an experiment.

In this experiment, many different computers are asked to compute a quantity and return the result to a main computer. The list that you have to process is the collected results.

  • To see what the list looks like, use getcopy to get two programs into your account:
getcopy hw8b.py
getcopy montecarlo.pyc


  • Run the hw8b.py progarm it and observe the output:
python hw8b.py
------------------------------
N= 10000000
pi=3.16159265359
Job 1 stopped: Execution time:3.073 seconds
------------------------------
N= 10000000
pi=3.15159265359
Job 2 stopped: Execution time:3.023 seconds
------------------------------
N= 10000000
pi=3.15159265359
Job 3 stopped: Execution time:3.029 seconds
------------------------------
N= 10000000
pi=3.14159265359
Job 4 stopped: Execution time:3.015 seconds
...
...
...
------------------------------
N= 10000000
pi=3.14159265359
Job 88 stopped: Execution time:3.021 seconds

All we have to do to