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.
Download the solarsystem.py file we have been working with.
Modify the Planet class as shown in Listing 10.12.
Modify the Planet class shown in Listing 10.13.
Modify the createSS function to include initial x and y velocities, as in the corresponding lines of Listing 10.15.
Do some initial testing:
Create a solar system using createSS and assign the result to the variable ss.
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.
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.
For the first planet of ss, use setXVel and setYVel and check that the velocity changed.
For the first planet of ss, use moveTo and check that the results of getXPos and getYPos changed.
Modify the SolarSystem class as shown in Listing 10.14.
Define the createSSandAnimate function essentially as in Listing 10.15, but using a call to createSS in 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 Planet class 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 getXPos and getYPos methods to work without the stored values.
Test that everything still works; in particular, show an example test other than just createSSandAnimate().
Simplify the moveTo method to remove code that has become extraneous.
Test that everything still works; in particular, show an example test other than just createSSandAnimate().
For this project, send an email message to max@gustavus.edu that includes the following items:
Your complete program file, incorporating all the changes you made.
The input and output for each test you needed to carry out.
Your answer to the question which planet has the shortest year.
You will earn one point for each of the following accomplishments:
You modified the Planet class as shown in Listing 10.12.
You modified the Planet class shown in Listing 10.13.
You modified the createSS function to include initial x and y velocities, as in the corresponding lines of Listing 10.15.
You created a solar system using createSS and assigned the result to the variable ss.
You used a loop or list comprehension to operate on each planet of ss.
You used getXVel correctly.
You used getYVel correctly.
You correctly retrieved the first planet of ss.
You correctly used setXVel and setYVel.
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 SolarSystem class as shown in Listing 10.14.
You defined the createSSandAnimate function as described.
You correctly stated which planet has the shortest year.
You changed the __init__ method not to store the values.
You changed the getXPos and getYPos methods 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 moveTo method.
You showed the input and output from an example test conducted after the moveTo change, and that test is not createSSandAnimate().