Click here to Skip to main content
6,635,160 members and growing! (17,634 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Game Development » Games     Intermediate

Insect Life Simulation

By ashvin

An article on insect life simulation.
C#, VC7.1.NET 1.1, Win2K, WinXP, Win2003VS.NET2003, Dev
Posted:2 Jan 2004
Views:62,756
Bookmarked:11 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 2.19 Rating: 1.81 out of 5
10 votes, 62.5%
1
2 votes, 12.5%
2
1 vote, 6.3%
3
1 vote, 6.3%
4
2 votes, 12.5%
5

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

About the Author

ashvin


Member
Senior Software Er.
Aspect Communication
San Jose USA CA


Occupation: Web Developer
Location: United States United States

Other popular Game Development articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
AnswerTry This Pinmembernkka21:41 13 Mar '08  
GeneralGranted. PinmemberKinlan12:59 4 Jan '04  
GeneralRe: Granted. Pinmemberdog_spawn13:07 4 Jan '04  
GeneralRe: Granted. PinmemberKinlan13:13 4 Jan '04  
GeneralRe: Granted. PinmemberKinlan13:18 4 Jan '04  
GeneralRe: Granted. Pinmemberdog_spawn13:23 4 Jan '04  
GeneralRe: Granted. PinmemberKinlan13:31 4 Jan '04  
GeneralRe: Granted. PinmemberdzCepheus13:12 5 Jan '04  
GeneralRe: Granted. PinmemberKinlan14:07 5 Jan '04  
GeneralHmm... PinmemberdzCepheus18:23 3 Jan '04  
GeneralRe: Hmm... Pinmemberdog_spawn6:10 4 Jan '04  
GeneralRe: Hmm... PinmemberdzCepheus11:24 4 Jan '04  
GeneralRe: Hmm... Pinmemberashvin11:57 4 Jan '04  
GeneralIdiot Pinmemberdog_spawn12:03 4 Jan '04  
GeneralRe: Hmm... PinmemberdzCepheus12:25 4 Jan '04  
GeneralDelete this article Pinmemberdog_spawn12:09 4 Jan '04  
GeneralRe: Delete this article Pinmemberschor20:58 26 Jan '04  
GeneralI agree, but Pinmemberdog_spawn6:57 27 Jan '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Jan 2004
Editor: Smitha Vijayan
Copyright 2004 by ashvin
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project