NetLogo banner

NetLogo Publications
Contact Us

Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Farsi / Persian


NetLogo User Community Models

(back to the NetLogo User Community Models)

[screen shot]

If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".(The run link is disabled for this model because it was made in a version prior to NetLogo 6.0, which NetLogo Web requires.)


The Worm simulation is a model of a population of virtual "worms". The model explores the relationship between individual behavior and population dynamics. It can easily stand alone, but it was developed as an enrichment activity following several weeks of a standard mealworm biology lab. It is suitable both for an introduction to population dynamics, and as an introduction to agent-based modeling in biology. Although quite simple, the simulation can produce complex dynamics that could be suitable for discussion up through a high school level.


The simulation consists of essentially just two elements, a field of "grass" which is the food source of the worms, and the worms themselves. We measure the grass in terms of its "length", which is recorded in the _grass_ variable owned by patches. The grass also grows at a rate defined by the Growth_Rate slider, with length going from zero (black patch color) up to a maximum defined by the MAX_GRASS_HEIGHT constant (bright green patch color). The worms own _life_ and _energy_ attributes. Energy derives from food consumed, while life (lifespan) acts as a counter limiting the amount of time the worm has left to live. In each tick, worms 1. crawl, 2. eat, 3. metabolize and 4. reproduce.

1. crawl - this is essentially random motion forward and within 20 degrees to the left or right
2. eat - worms eat any grass available in their square in each tick, cropping a length defined by the Food_Conversion slider (if that much is available - otherwise the worm does not eat); this then increases the worm's _energy_ variable by 1 unit (a "calorie"), up to the maximum defined by the Energy_Reserve slider.
3. metabolize - the worms' _life_ counter is decremented, as well as the _energy_ counter (by 1/2 a calorie); when there is abundant food, a worm's lifespan is doubled. Either old age or starvation may kill a worm.
4. reproduce - every worm that has at least half of its maximum energy (defined by Energy_Reserve) has a chance of asexually reproducing a single offspring given by Reproduction_Rate. When food is abundant, the reproduction rate essentially gives the per-tick growth rate of the worm population (not accounting for death of old worms).

The interaction of resource-dependent population growth with resource limitations gives rise to surprisingly complex population dynamics. At the beginning, unbounded exponential growth is observed. As the worm population approaches the environment's carrying capacity, growth saturates and, depending on the rate of grass regrowth and the maximum energy reserve per worm, the population may experience a mass die-off due to starvation. In this case, eventually the population rebounds and after several oscillations will stabilize at some intermediate value. Otherwise, the population simply levels off.


As mentioned above, this simulation was originally developed as a follow-on to a mealworm biology lab, but can easily stand alone. The virtual "worms" in this simulation are far simpler than real mealworms (which are actually beetle larvae, not real worms). It is helpful to introduce the simulation starting with just a single worm and introducing the four behaviors one by one. The simulation can be run with each of the four behaviors (described above) commented out and then incrementally uncommented. In particular, commenting out the "metabolize" function in the "to live" procedure essentially turns off the worms' life counter, meaning that no worms die. This is a good way to show the consequences of unbounded population growth, given the (unrealistic) assumption that there are no limitations on resources.

As usual, "setup" should be executed before "go".

The various sliders, some of which discussed are above, control the following variables:
- Initial Population. This should be self-explanatory. Note that the initial population is generated by the "setup" procedure, so changes to this (and other) sliders are generally not registered after setup is executed.
- Life Span. The number of ticks that each worm lives (this number may be doubled if abundant food is available at each span of time).
- Reproduction Rate. The fraction of well-fed worms (i.e. having at least half the maximum energy reserve) that reproduce per tick. Reproduction corresponds to asexual budding. Individuals reproduce probabilistically.
- Energy Reserve. This specifies how many excess "calories" a worm can accumulate for consumption when food is not available. Any worm that runs out of food will starve (die). A worm can produce up to 1 calorie of energy from eating per tick, while 1/2 a colorie is consumed by living. Hence, excess energy is accumulated at a rate of 1/2 calorie per tick (while food is abundant).
- Food Conversion. This specifies what length of grass is cropped by a feeding worm to produce 1 calorie of energy. This is inversely equivalent to the worm's gain from food.
- Growth Rate. This specifies how fast the grass grows, i.e. by what amount (per tick) it is increased, up to the maximum.


The Food_Conversion slider has a direct impact on the steady-state carrying capacity of the environment. It also has indirect effects on the dynamics of the population. For instance, a very large value of Food_Conversion has the effect of reducing the reproduction rate, since it is relatively more difficult for a worm to obtain enough food to eat. Coupling large Food_Conversion with small Life_Span values may easily make the worms go extinct.

The combination of a large reproductive rate with a high Energy_Reserve value might seem to be quite advantagous to a worm population. However, this combination tends to have the unexpected effect of sustaining a population boom that exhausts the carrying capacity of the environment (particularly when grass regrowth is slow), resulting in mass die-offs and cycles of population boom and bust that may or may not stabilize. When the Energy_Reserve value is low, and lifespan short, the population of worms tends to respond directly to the amount of food available, rather than with a time lag, and hence rather than oscillating the population merely plateaus at the carrying capacity.


A number of basic questions can be answered with this model. What is the effect of initial population on final population? (It effectively jumps the clock forward, but otherwise has no effect). What is the effect of reproductive rate and life span on final population size? And so on.

For more advanced classes, it is interesting - and challenging - to characterize what combinations of parameters produce:
- oscillating vs. stable populations
- the highest (or lowest) carrying capacity

It is also interesting and challenging to describe the population dynamics analytically. This is discussed more below.


This model can be extended in a number of ways. A trivial extension that would be appropriate to relate the model to some other real-life lab (such as bacterial growth) would be to change the turtle appearance from a worm to some other creature (especially for students who may feel squeamish about worms!) Similarly, characteristics of grass growth, worm metabolism, etc. may all be tailored.

One basic extension that was used with an earlier version of this model was to add a population of birds that preyed on the worms. This gives rise to familar predator-prey dynamics. It is also straightforward to add some characteristic (such as length) to worms which affects their food gain, to see how random variations in that characteristic may over time lead to natural selection for longer or shorter worms. A characteristic such as length may also, when predators are present, be used to illustrate competing influences on survival. For instance, large worms may live longer (and hence produce more offspring), but may be easier prey for birds.

It would also not be difficult to add state variables that could be used to plot ideal population dynamics according to standard exponential growth and decay models, so that comparative analysis could be accomplished.


The Wolves and Sheep model is similar in some respects. There is also a more mathematically oriented population dynamics model in the library which can be related to this one.


This model was written by Mathew Davies through the NSF-sponsored GK-12 program at the School of Engineering and Applied Sciences at Columbia University, for use in 8th-grade science classrooms at I.S. 143 (Eleanor Roosevelt intermediate school, Washington Heights) in Manhattan, New York in the fall of 2004. The author may be contacted at the email address:

This simulation, along with other technology-based classroom resources, may be found at the website

(back to the NetLogo User Community Models)