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
-
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. 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 evaluatingcreateSS()in the Python shell. Do this now and see what happens. One warning: sinceplanetarySimulator.pyimports the three class files, you will need to be sure you save all files before runningplanetarySimulator.py, since Python will simply load the most recently saved versions of those other files.Modify the
Planetclass as shown in Listing 10.12.Modify the
Planetclass shown in Listing 10.13.Modify the
createSSfunction to include initial x and y velocities, as in the corresponding lines in the createSSandAnimate procedure of Listing 10.15.Do some initial testing:
Create a solar system using
createSSand assign the result to the variabless.For each planet of
ss, usegetXVeland 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.For each planet of
ss, usegetYVeland 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.For the first planet of
ss, usesetXVelandsetYVeland check that the velocity changed.For the first planet of
ss, usemoveToand check that the results ofgetXPosandgetYPoschanged.
Modify the
SolarSystemclass as shown in Listing 10.14.Define the
createSSandAnimatefunction essentially as in Listing 10.15, but using a call tocreateSSin place of many lines.Use the animation to determine which planet has the shortest year. (That is, which orbits the sun in the least time.)
Modify the
Planetclass to not directly store the planet's x and y position, but instead use the turtle's position:Change the
__init__method not to store the values.Change the
getXPosandgetYPosmethods to work without the stored values.Test that everything still works; in particular, show an example test other than just
createSSandAnimate().Simplify the
moveTomethod to remove code that has become extraneous.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:
You modified the
Planetclass as shown in Listing 10.12.You modified the
Planetclass shown in Listing 10.13.You modified the
createSSfunction to include initial x and y velocities, as in the corresponding lines of Listing 10.15.You created a solar system using
createSSand assigned the result to the variabless.You used a loop or list comprehension to operate on each planet of
ss.You used
getXVelcorrectly.You used
getYVelcorrectly.You correctly retrieved the first planet of
ss.You correctly used
setXVelandsetYVel.You did appropriate checking to see that the first planet's velocity actually changed.
You correctly used
moveTo.You did appropriate checking to see that the first planet's position actually changed.
You modified the
SolarSystemclass as shown in Listing 10.14.You defined the
createSSandAnimatefunction as described.You correctly stated which planet has the shortest year.
You changed the
__init__method not to store the values.You changed the
getXPosandgetYPosmethods to work without the stored values.You showed the input and output from an example test conducted after the above changes, and that test is not
createSSandAnimate().You removed extraneous code from the
moveTomethod.You showed the input and output from an example test conducted after the
moveTochange, and that test is notcreateSSandAnimate().