Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Insect Life Simulation

0.00/5 (No votes)
2 Jan 2004 1  
An article on insect life simulation.

Sample screenshot

Introduction

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.

  1. Insect will always die on end of life. End of life is 10 second (hard coded to get good pattern).
  2. If two Insects are live then it will result in new Insect birth.
  3. If three or more Insects live near, then one Insect will die because of over crowd.

Memory requirement.

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.

Code description.

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.

Sample screenshot

Known Issues:

  1. Cannot accept any command until all Insect creation is finished.
  2. On close, it is not clearing instance of application, so clean it using task manager.

Enjoy simulation.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here