CS 111
Fall 2016
Introduction to Computer Science
HW08: Ocean simulation
Due: Monday, 10/24 at 23:55
Prelude
In Lab 04, as a class, we collaboratively coded up Pacman
, a cool new class using Zelle's graphical library. It commands more primitive graphical elements such as Circle
and Polygon
, implements a few standard methods such as draw
, undraw
, and move
, a few important methods such as __init__
, makeParts
, and step
, and a method reverse
just for fun.
I polished it a bit to do the things we discussed in the last 5 minutes of class and put it as pacman.py. You can download and run it directly, or use pacmantest.py (requires pacman.py
to be in the same directory) to run a more extravagant test. This demonstrates how pacman.py
can be run directly but also import
ed as a module.
If you compare pacman2.py (what we had in class) and pacman.py
(polished), you'll see that I mostly used what you wrote. The makeParts
function underwent the most amount of change, but I actually used code that another group sent me, so this is very much yours as well!
The program
For this assignment, your job will be to write a program showing an animation of a simple underwater scene. Your final program, when runnning, should display a randomly generated collection of fish and bubbles against a suitably watery background (just blue, for example, is suitably watery). As the animation proceeds, the fish should swim back and forth (switching directions when they hit the sides of the window) and the bubbles should rise. When a bubble hits the top of the screen, it should disappear and be replaced by a new randomly generated bubble at the bottom of the screen.
Put your Fish
class in a file called fish.py
.
Put your Bubble
class in a separate file called bubble.py
.
Your main program should be in a file called ocean.py
,
which will import
both the fish module and the bubble module.
If you find this program straight-forward, feel free to add extra features--waving plants (that generate bubbles), vicious sharks (that eat fish), submarines (that explode when clicked), self-solving Rubik's cubes, or whatever strikes your fancy. These extra goodies, however, should be pursued only for your own pleasure; a straight implementation of the ocean as described in the previous paragraphs will be eligible for full credit.
Like the previous graphics homework, I may show some especially impressive work in class. If you do not want your work shown, please mention this in the comments at the top of your ocean.py
.
Submission
Upload to Moodle three files: named fish.py
, bubble.py
, and ocean.py
, as described above.
Optionally, you may use zip
or tar
to package all your project files as a single archive file,
and upload that instead.
This is especially applicable if you add a lot of extra features (each in its own file!),
and it becomes cumbersome to upload one file at a time to Moodle.
Suggestions
For the basic motion of the
Fish
andBubble
objects, you should feel free to borrow liberally fromPacman
. Generating random objects, which you'll need to do, is demonstrated in pacmantest.py, so again, borrow and adapt as needed.-
Replacing the bubbles at the top with bubbles below require some care:
when a
Bubble
object disappears at the top of the ocean, make sure to either remove thatBubble
from your bubble list, or reuse it by resetting its x and y coordinates. Don't just build an ever largerbubbleList
--that will gradually slow your program down as it keeps trying to move bubbles that are no longer visible. - As always, I strongly recommend that you create an iterative
development plan for yourself. What happens in Phase 1, Phase 2,
Phase 3, etc. of your work, and how will you test each phase?
Even if you get only a couple phases done (e.g., your
Fish
swim in only one direction and yourBubble
s don't regenerate), you'll have a functional and partially complete project to hand in, which will be worth more points than if you attempt to do everything specified but your code does not run. - For good style, follow the example of the
Pacman
module: running the file directly viapython3 pacman.py
shows a simple module demo (test), butimport
ing the module does NOT run anything. This ought to fit well with the iterative development plan from the suggestion above.
This is a somewhat long assignment. Start early! Ask questions. Have fun!