Simulation of Butterflies
(View Java Source Code of Mimesis)
(View Java Source Code of Stack)

In London, before the Industrial Age, peppermoths made their home on white birch trees. Some blended into their surroundings, and the more visible ones became lunch for local birds. As the Industrial Age began, soot created from factories burning coal gave the city's trees a darker haze. As a result, what were previously hidden moths became obvious to the hungry birds. Several generations of moths later, it seemed the species was nearly all dark in wing color, in stark contrast to the description of the species several years beforehand.

This program exemplifies that scenario. Choose a background color and click "See It" to see what would happen to a group of butterflies.

Here is how my algoritm is working:

1. The program creates a set of butterflies with a random wing color, which is a value between 0 and 255. The butterflies are then placed onto an image with a background color that has been selected.
2. A "bird attack" occurs, in which highly visible moths are eaten. Visibility is determined by probability: 1 / |background - wing color| + 1. (A color difference of 0 yields a visibility of 1.) A randomized number is compared to the visibility rating, and should that number be greater than the visibility, the butterfly is considered eaten. This ensures that butterflies with a low visibility probability are less likely to be eaten than those with a greater wing-to-background color difference.
3. A random set of surviving butterflies are chosen, and a mutation of that butterfly is placed into a vacancy made by an eaten butterfly. The mutation is made by either adding or subtracting a random value (between zero and the mutation radius, in this case 0.50) from the "parent" butterfly's wing color ID. Care is taken to ensure no "child" butterfly creates offspring for the current generation.
4. Using this current pool of butterflies, the process repeats from step 2 ad infinitum.


 
-------
© 2002, 2003 M. Tartàglia