This program simulates Insect (Bugs or Virus) life cycle. All Insects have some life cycle. They are born, then live for their life period, or die before their life period because of some reason. Here is one Insect life cycle simulation program using some life rules. The rules are listed in the rule section. The program is implemented in C#.
How it works
Once you will run demo program and press Insect>>Draw menu, it will create all possible green boxes on screen. Each box represents Insects. Green color indicates Insect is dead and Red color indicates Insect is alive. (I chose red color for live status because initially I decided the title "Virus Life simulation", and virus are not good whenever they are live, but then I changed the title thinking that the word "Virus" always makes the impression of computer virus for programmers.) You can change the state of an Insect by clicking on it. If you make some Insects live which are near of each other it will generate a pattern followed by life cycle rule.
Life cycle rule.
- Insect will always die on end of life. End of life is 10 second (hard coded to get good pattern).
- If two Insects are live then it will result in new Insect birth.
- If three or more Insects live near, then one Insect will die because of over crowd.
This demo program draws 16*16 pixel possible box for each Insect. Each Insect is an instance of the
InsectControl class and it holds memory. In my computer, I have 1152*864 screen resolution, which allows me to create ~ 4000 Insects and takes 22MB memory. So, memory requirement depends on screen resolution for this application.
I created a user control called
InsectControl. This control has a timer with 1 sec interval to update the status of the Insect. Each Insect holds information about its children. Each Insect will have maximum 8 children (see in figure). Insects which are on the corner will have less children. Every second, each Insect will check their child status and follow the above rules to decide its own status.
- Cannot accept any command until all Insect creation is finished.
- On close, it is not clearing instance of application, so clean it using task manager.
Senior Software Er.
San Jose USA CA