gskinner.com: gBlog: FlashMX 2004 source code, news, reviews and opinions
Back to gBlog Main gskinner.com website: source code, portfolio, etc. contact Grant Skinner

Syndication
RSS 1.0
RSS 2.0


Subscribe
Enter your email address to be notified when posts are added.

Search

Resources
Conference Session Notes

Flash Blogs
Waxpraxis
Philterblog
W3Blog
Jonas Galvez
Josh Dura
Quasimondo
Flashguru
Sean Voisen
Colin Moock
Flazoom
Greg Burch
Pope De Flash
Peter Hall
Glyn Thomas
actionscript.com
Princess Pegg


Aggregators
Flog
FullAsAGoog
MXNA
Hall of Justhese


« Experiment: Grid Based Proximity | Back to Main | Experiment: Crystallization simulation »

April 14, 2004


IMPORTANT NOTE: This is an old archive. It is only here to support outdated external links. To view the updated version of this archive, please go to the blog index, and search for the title of this document using the search form.

Experiment: 6kb ecosimulation in Flash
Posted by Grant

I've always been interested in mimicing organic systems in Flash, and tolerance based behaviours in particular. When I built out my ProximityManager class, the first thing I thought of building with it was a simple aquatic ecosystem, here's my first attempt....

This eco-system is only 6kb in size (well, 27kb with the sprites and background image) but manages to acheive some fairly complex, organic behaviours as a result of using a tolerance methodology. It contains 3 different organisms, each with their own set of tolerances and behaviours:







Food:
These little white sprites don't really do much except drift in the tide. They only exists in the upper region of the ecosystem, and are the energy source all other organisms rely on (directly or indirectly). Over time, they lose energy and shrink until they die and are removed from the system. Larger, more energy rich Food drifts at higher depths, which rewards more aggressive Prey organisms.


Prey:
These orange sprites are the most complex organism in the system. They survive by eating the Food near the surface, but predatorial pressure forces them to return to the depths when they aren't hungry. As their energy levels drop, they shrink in size until they die and are removed from the system. When hungry, they will move to the surface and pursue any Food within their range.

They have a number of tolerances that govern their behaviour, including a depth preference, a tolerance for hunger and a tolerance for "fear". Their speed also varies - higher speed improves their ability to chase food and escape enemies, but also increases the rate at which they burn energy.

When their energy needs are satisfied, they may move to the surface to try to reproduce asexually - if successful, they will create a single child which shares most of their traits, mutated slightly. In this manner, a form of evolution occurs in the system over time (you may notice that the Prey get faster and more skittish if you let it run for awhile).

When scared by being chased, or merely by the presence of a Predator (larger predators are more frightening), they will beat a hasty retreat to the depths. They are less aware of Predators while chasing a Food sprite, and are oblivious to threats while reproducing.


Predator:
The large "jelly fish" sprites are Predators. They drift into the system randomly, and there can be up to 3 predators in the system at a time. Predators swim slowly and aimlessly, until they become hungry or a Prey organism catches their attention. Like Prey, different Predators have different tolerances for hunger, and different speeds. As their energy decreases, they will shrink until they die and are removed from the system.

When hungry, Predators will search for Prey, and then rush at them quickly in an attempt to eat them. While attacking, Predators will constantly look for a bigger, closer meal to chase. Predators are sensitive to pressure however, and cannot follow Prey below their individual depth tolerance. When a Predator catches a Prey organism, its energy is added to the Predators and the Prey is removed from the system.


The ecosystem does a pretty good job of maintaining balance. Prey population is controlled by predation and Food availability. Predators are limited by Prey population. I have seen the system die when 2 or 3 fast predators over-hunt the Prey, but hey, that happens in real life too.

I'll probably tweak the numbers further, and add some more behaviours in the future, but I thought this was a decent first try.

Cheers.

Posted @ 10:39 AM by Grant | TrackBack


Comments

Vrr nice; I wish I could put this as the background of my 2nd monitor; for now, it's a nice browser window shrunk to fit on my desktop. Nice job, mangxt!

Posted by: JesterXL at April 14, 2004 11:20 AM

It looks so pretty!

Posted by: Vera at April 14, 2004 11:34 AM

Nice work Grant, wish I had more time to do stuff like that ;) Reminds me of that shark simulation thing Sam Wan did a couple of years back, very cool simulation stuff.

Posted by: Peter at April 14, 2004 11:48 AM

Very cool ... It might be nice to be able to toggle the background on and off so you can see the interaction a bit better.

Posted by: Daniel Wabyick at April 14, 2004 12:28 PM

once again.. you're a madman..
Nice work Grant!

(you should add a pollution "layer".. a kind of a predator that effects both the prey and their food source..)

Posted by: Bob Clagett at April 14, 2004 12:44 PM

Cool work, I like the jelly fish most... I´m looking forward for mutants ;-)... I had a project a few terms ago at university ... not in flash, but evolution rocks anyway =)http://bitlife.pl-visions.com

Posted by: ripcurlx at April 14, 2004 01:08 PM

Awesome! I always wished and still hope i would do something like this..

It makes me crazy, great stuff Grant

Posted by: Abdul Qabiz at April 14, 2004 02:34 PM

If you leave it up long enough, they all die.. but really really cool!

Posted by: Graeme Bull at April 14, 2004 10:59 PM

Your are a master Grant! Congrats, it's really beauty to hang watching : )

Posted by: Carlos Rovira at April 15, 2004 10:29 AM

Simply amazing.

Posted by: Simon Wacker at April 15, 2004 11:41 AM

All very interesting stuff.. Looking forward to the talk on the 19th.

Posted by: Tom Gooding at May 13, 2004 01:26 PM


Hosting by NetKeepers.ca | Powered by Movable Type 2.661
The text content of this blog is licensed under a Creative Commons License. Graphics are ©2003 Grant Skinner.