Click here to Skip to main content
15,881,715 members
Articles / Programming Languages / C#
Article

Insect Life Simulation

Rate me:
Please Sign up or sign in to vote.
1.39/5 (19 votes)
2 Jan 20042 min read 106.6K   1.1K   16   18
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


Written By
Web Developer
United States United States
Senior Software Er.
Aspect Communication
San Jose USA CA


Comments and Discussions

 
AnswerTry This Pin
nkka213-Mar-08 0:41
nkka213-Mar-08 0:41 
GeneralGranted. Pin
Kinlan4-Jan-04 11:59
Kinlan4-Jan-04 11:59 
GeneralRe: Granted. Pin
dog_spawn4-Jan-04 12:07
dog_spawn4-Jan-04 12:07 
GeneralRe: Granted. Pin
Kinlan4-Jan-04 12:13
Kinlan4-Jan-04 12:13 
GeneralRe: Granted. Pin
Kinlan4-Jan-04 12:18
Kinlan4-Jan-04 12:18 
GeneralRe: Granted. Pin
dog_spawn4-Jan-04 12:23
dog_spawn4-Jan-04 12:23 
GeneralRe: Granted. Pin
Kinlan4-Jan-04 12:31
Kinlan4-Jan-04 12:31 
GeneralRe: Granted. Pin
dzCepheus5-Jan-04 12:12
dzCepheus5-Jan-04 12:12 
GeneralRe: Granted. Pin
Kinlan5-Jan-04 13:07
Kinlan5-Jan-04 13:07 
GeneralHmm... Pin
dzCepheus3-Jan-04 17:23
dzCepheus3-Jan-04 17:23 
GeneralRe: Hmm... Pin
dog_spawn4-Jan-04 5:10
dog_spawn4-Jan-04 5:10 
GeneralRe: Hmm... Pin
dzCepheus4-Jan-04 10:24
dzCepheus4-Jan-04 10:24 
GeneralRe: Hmm... Pin
ashvin4-Jan-04 10:57
ashvin4-Jan-04 10:57 
GeneralIdiot Pin
dog_spawn4-Jan-04 11:03
dog_spawn4-Jan-04 11:03 
GeneralRe: Hmm... Pin
dzCepheus4-Jan-04 11:25
dzCepheus4-Jan-04 11:25 
GeneralDelete this article Pin
dog_spawn4-Jan-04 11:09
dog_spawn4-Jan-04 11:09 
GeneralRe: Delete this article Pin
schor26-Jan-04 19:58
schor26-Jan-04 19:58 
GeneralI agree, but Pin
dog_spawn27-Jan-04 5:57
dog_spawn27-Jan-04 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.