CSC111 Lab 8

From dftwiki3
Revision as of 10:45, 24 March 2010 by Thiebaut (talk | contribs) (Moving Ball, Part 1)
Jump to: navigation, search

This lab deals with the moving ball example we saw in class recently. Your work for today is to add new functionality similarly to the way we added functionality to the graphics example with buttons.

You should start the Mac in Mac OS mode for today (graphics is more easily done this way). Make sure you start the X11 utility first, then the Terminal window.

Moving Ball, Part 1

  • Create a program called movingBall.py, which contains the version we ended up in class yesterday. It is available here.
  • make sure the graphics.py library is in the same directory where your program is located.
  • Run the program and make sure it works.
  • Clean up the testing of x and y coordinates of the center, in the function simul(), so that it is simpler. Use AND or OR to simplify the testing.
  • Verify that your ball still moves well. You may increase the number of simulation steps in simul to make the simulation go longer.

Moving Balls, Part 2

  • Add an extra ball to the simulation. The result should be two balls moving around the box and bouncing off the sides.
  • You will need to create a new circle, say c2 in main(), and pass it to the simul() function as well. But make sure simul() contains only one for-loop. The same for-loop should move both balls around.