Firefly communication through bioluminescence is a beautiful thing to watch, and I felt it could be easily modeled using my ProximityManager class, and a simple tolerance/potential system. I tried to make this system mimic the real interaction of Fireflies in nature, and was inspired by an article I found about an artist’s video of Fireflies in a Malaysian rain forest.
The Firefly sprites in this simulation fly around the screen, completely invisible in the dark. There are 350 Fireflies in the system, 90% male, 10% female. Female Fireflies blink at semi-random intervals – the light excites nearby males, who in turn may blink. This potentially triggers a cascade as males blink and excite other males (kind of kinky) who blink in turn, creating waves of light.
The more excited a Firefly is when it blinks, the brighter and whiter it glows (hence producing more light, and exciting other Fireflies more). This is achieved with simple scaling, alpha, and color transformations.
This experiment was very easy to code, but if took awhile to balance the tolerances and values to achieve the desired effect. I’m quite impressed that the Flash 7 player has enough power to track 350 sprites with this kind of behaviour as effectively as it does.
I’m going to be doing a show and tell about the code behind this experiment at the Edmonton Flash User Group meeting tomorrow, and might release the code on my blog in the next little while.
Here is all 2kb of it: