Fish Tank Simulator, version 1

Click in the tank to release pellets for the hungry (green) fish!

Go, fish, go. In version 1 above, the fish start as babies, grow into breeding adults, and eventually die of old age. They can swim freely around the tank based on their moods. The fish also have hunger levels and will die if they go hungry unless the user feeds them by clicking in the tank to release pellets.


Screenshot from Fishtank Simulator 2.0

Version 2 is a modified version of the fishtank simulator used to teach middle school children basic concepts of programming. I simplified the code and worked with the kidsTeam members for 5 weeks on this project, adding a small piece of new functionality to the tank while learning a new programming concept. Aside from overall simplification of behaviors and abstraction of code to allow them to only see relevant parts of the lesson for the day, the fishtank also changed in nature as the kids experimented with code and I raced ahead of them each week to build and plan the next lesson to their interests. In Fishtank 2.0, each fish has a life bar floating above its head. The fish takes damage when it contacts falling garbage and gains health back when it consumes pellets released by the user clicking the mouse in the tank. The fish also cycle colors fluidly using color objects.

Extended details on the design of version 1.0:

The fish each have a uniquely generated lifespan from 60 to 90 seconds long. They start off as tiny babies and will grow until they reach adult size. The shift from adolescent to adult is not timed, but based on the fish's physical growth. As an adult, the fish becomes fertile. When two fertile adults collide, one of the fish will become pregnant. A pregnant fish turns red and is not fertile during pregnancy and can not terefore impregnant other fish. After the gestation period, the fish will lay an egg. The fish can lay eggs while hungry. The fish returns to its normal adult coloring and the egg floats to the bottom of the tank to hatch. The adult fish can have at most 2 offspring. When the fish is too old, it will die, illustrated when the fish goes belly up, ghosts out in a blue color, and sinks to the bottom of the tank and disintegrates. If the fish is pregnant when it dies of old age or hunger, the pregnancy is also terminated.

The fish are now moody swimmers. The fish's "mood" is it's preference on how fast it will swim, for how long, and in what direction. The fish randomly generates it's behavior for the next mood and will move accordingly until its mood shifts and a new mood is generated. If it hits a tank wall, it bounces but otherwise continues in its chosen mood. The fish can also hover in place if it chooses to.

The user can click in the tank to release food pellets. The simulation is limited it to only 5 pellets on screen at once, so it gets harder to feed many fish. If not eaten, the pellets will fall down to the floor of the tank and disintegrate.

A fish will get hungry after a maximum period of 40 seconds. The fish are initially generated with a random hunger level lasting between 20 and 40 seconds. When the hunger level gets critically low, the fish will get distressed and hungery and turn green. In this distressed state, the fish will look for food pellets. If there are no pellets available, the fish will continue to swim normally. If there is one or more pellets available, the fish will calculate the distance between itself and each pellet and decide to chase the closest pellet. It recalculates the distance on every frame and will change its target pellet if a new pellet appears closer. If all available pellets disappear (eaten or dinintegrated), the fish will return to its normal swim behavior until it spots another pellet. If the fish is pregnant when it gets critically hungry, the fish will still turn green, but will turn back to red if still pregnant after eating a pellet.

The pellets are self-cointained objects with their own class file. They are released when the user clicks and the click is picked up by the _root timeline. The _root timeline attaches a new pellet to itself and positions it at the click location. The pellet class takes it from there, animating down and dinintegrating. The pellets are kept in an array on the _root timeline in the same way that the fish are kept in a _root timeline array (see Lab 2 discussion), and the fish handle all of the pellet hittesting through this array.

The statistics at the top of the screen are not necessary, but they are interesting to watch as the simulation runs. They reflect a few of the many changes occurring behind the scenes. The background animations are a few quick tweens inside of looping movie clips to make the scene more interesting. The sounds are all freeware from www.flashkit.com

This project was interesting to put together. I'm pleased with how the fish's moody swimming behavior came out for how I decided to put it together. I played with the parameters and just sat and watched the simulation run until I was happy with the overall feel. I wanted it to look more natural but not go over the top calculating curved paths. But the curves have sparked my interest and on the list for version 3.0...

I also had to think back to high school math for this one. Thank you Pythagoras for making the distance calculation between pellet and fish a straight-forward operation. After that, it took me a bit of thinking to work out the logic for the chasing different pellets behavior.

There are still a few bugs I haven't worked out yet (though I've fixed all major ones already). Email me if you find something: brittany.steiner@ubalt.edu

I made some decisions on what to cut and what to add to this simulation with the specifc goal of making it easier to interact with and understand. I was actively trying to cram as many interesting behaviors and widgits into this project while stripping out anything that made the user's experience too complicated or less interested.I also went with whatever interested me most, and so the curved paths are on the list fo rthe future. I'd probably also make the pellets have to hit the fish's mouth area instead of just hitting any part of the fish like it does now. I would also add some sounds to make the user experience better. The sounds are secondary to the fish behavior so I didn't bother in this version.

I also want another way to kill the fish. I tried a variety of lifespans and if they were too short the fish kept dropping off and took away some of the fun quickly. So if I took this farther, I would want some scenarios to see what the fish do under certain conditions. Example idea tangent: two fish types A and B. Adult As will eat adult Bs, but Bs will eat juvenile or egg As. If we start with equal amounts, do the populations maintain their numbers or do they drive each other to extinction? If we start unbalanced, will the poulations plot sine waves and reach a harmonic equilibrium, or will they gradually drive each other to extinction? Will they reach an equal number of members in their populations and maintain that equality? What if I add stress sliders, such as amoutn of pollution or temperature variations, and they affect the fish types differently. How will these populations be affected? This is where the simulation is starting to get really interesting to me, when I can use my system to do something greater with it, allow it to show me something. And if I started off with data sets representing real fish species, then the prediction data gains a value in the real world outside of this Flash sandbox.

On a final note, this project was really 80% thinking and 20% coding. I spent a lot of time thinking about what I wanted to do and how I could do it before I even thought about touching the Actionscript files. When I moved into the coding portion, I worked in a piecemeal fashion, implementing one new behavior and testing it completely before moving on to the next new component to introduce. The hardest part was cleaning up the logic errors I introduced at 3 a.m. Must sleep in later when I know I'm going to be up building this sort of project.

I've also loaded it with a few easter eggs. After clicking once into the movie (to give it focus here on the webpage), press 'H' to toggle the hunger behavior on or off; press 'B' to toggle breeding on or off; and press 'G' to toggle aging on or off. If you press 'A', all easter eggs will be toggled on or off together. Text will appear in the top right corner of the tank when each of the eggs are activated (and so will show only when variables are inactive).

You may also press 'S' to toggle into "Fish in a Barrel Mode" where you click to shoot and kill fish. I realise it's rather perverse to shoot fish in a barrel, but it's still entertaining. Helpful for when teh tank gets overpopulated and you jsut don't want to wait for the fish to die off from hunger. I've made this purposefully an easter egg since it doesn't really fit into the original, more serious fish simulation.

(Going to need a bigger tank...)


Copyright © 2010 | B. Steiner
britsteiner@gmail.com | updated: 2/6/2010

Portfolio Main Code Widgets Artwork Academic Writing Multimedia