MCS 177: Introduction to Computer Science I (Fall 2010)

Project 9: A Solar System Animation


Start: Thursday 12/2; Due: Wednesday 12/8, by the 12:30 p.m.

Overview

In this project, you will follow the steps shown in your textbook in order to animate the solar system model. You will then change the internal representation of planets' positions and observe that the animation continues working just the same with the new representation. This is because the animation accesses the planets' positions only through accessor methods, which provide a stable interface even when you change the underlying representation.

You are to do this project individually.

Specific tasks

  1. Download the following files we have been working with and save them somewhere in the same folder:


    The first three of these are the implementations of the classes SolarSystem, Sun, and Planet, and are taken directly from the book (with some bug fixes). The last file is the controller for the planetary simulator, also derived from the book.

  2. Open up all of these files in IDLE and take a look at what is there. In order to run the simulation, you should run the controlling module (planetarySimulator.py) in Python. You can then create the solar system by evaluating createSS() in the Python shell. Do this now and see what happens. One warning: since planetarySimulator.py imports the three class files, you will need to be sure you save all files before running planetarySimulator.py, since Python will simply load the most recently saved versions of those other files.

  3. Modify the Planet class as shown in Listing 10.12.

  4. Modify the Planet class shown in Listing 10.13.

  5. Modify the createSS function to include initial x and y velocities, as in the corresponding lines in the createSSandAnimate procedure of Listing 10.15.

  6. Do some initial testing:

    1. Create a solar system using createSS and assign the result to the variable ss.

    2. For each planet of ss, use getXVel and check that you get the initial value. Do this in a way that makes the computer do the work of stepping through the planets, rather than your manually dealing with each.

    3. For each planet of ss, use getYVel and check that you get the initial value. Do this in a way that makes the computer do the work of stepping through the planets, rather than your manually dealing with each.

    4. For the first planet of ss, use setXVel and setYVel and check that the velocity changed.

    5. For the first planet of ss, use moveTo and check that the results of getXPos and getYPos changed.

  7. Modify the SolarSystem class as shown in Listing 10.14.

  8. Define the createSSandAnimate function essentially as in Listing 10.15, but using a call to createSS in place of many lines.

  9. Use the animation to determine which planet has the shortest year. (That is, which orbits the sun in the least time.)

  10. Modify the Planet class to not directly store the planet's x and y position, but instead use the turtle's position:

    1. Change the __init__ method not to store the values.

    2. Change the getXPos and getYPos methods to work without the stored values.

    3. Test that everything still works; in particular, show an example test other than just createSSandAnimate().

    4. Simplify the moveTo method to remove code that has become extraneous.

    5. Test that everything still works; in particular, show an example test other than just createSSandAnimate().

Submitting your work

You will be submitting your code using Moodle; click on the following link for instructions on submitting code using Moodle. For this project, you will need to submit the following files:

  • Your final version of all of the modules: solarsystem.py, sun.py, planet.py, and planetarySimulator.py
  • readme.txt, which is a text file that contains:
    • The input and output for each test you needed to carry out
    • Your answer to the question which planet has the shortest year

Grading

You will earn one point for each of the following accomplishments:

  1. You modified the Planet class as shown in Listing 10.12.

  2. You modified the Planet class shown in Listing 10.13.

  3. You modified the createSS function to include initial x and y velocities, as in the corresponding lines of Listing 10.15.

  4. You created a solar system using createSS and assigned the result to the variable ss.

  5. You used a loop or list comprehension to operate on each planet of ss.

  6. You used getXVel correctly.

  7. You used getYVel correctly.

  8. You correctly retrieved the first planet of ss.

  9. You correctly used setXVel and setYVel.

  10. You did appropriate checking to see that the first planet's velocity actually changed.

  11. You correctly used moveTo.

  12. You did appropriate checking to see that the first planet's position actually changed.

  13. You modified the SolarSystem class as shown in Listing 10.14.

  14. You defined the createSSandAnimate function as described.

  15. You correctly stated which planet has the shortest year.

  16. You changed the __init__ method not to store the values.

  17. You changed the getXPos and getYPos methods to work without the stored values.

  18. You showed the input and output from an example test conducted after the above changes, and that test is not createSSandAnimate().

  19. You removed extraneous code from the moveTo method.

  20. You showed the input and output from an example test conducted after the moveTo change, and that test is not createSSandAnimate().