NetLogo banner

NetLogo Publications
Contact Us

Modeling Commons

Beginners Interactive NetLogo Dictionary (BIND)
NetLogo Dictionary

User Manuals:
Farsi / Persian


NetLogo Models Library:
Sample Models/Biology

(back to the library)


[screen shot]

If you download the NetLogo application, this model is included. You can also Try running it in NetLogo Web


This model demonstrates moths flying in circles around a light. Each moth follows a set of simple rules. None of the rules specify that the moth should seek and then circle a light. Rather, the observed pattern arises out of the combination of the moth's random flight and the simple behavioral rules described below.

Scientists have proposed several explanations for why moths are attracted to and then circle lights. For example, scientists once believed that moths navigated through the sky by orienting themselves to the moon, and that the moths' attraction to nearby, earthly light sources (such as a street lamp) arose because they mistook the terrestrial lights for the moon. However, while this explanation may seem reasonable, it is not supported by available scientific evidence.


Moths exhibit two basic kinds of behavior. When they detect a light source from a distance (as far as 200 feet away) moths tend to fly straight toward the light. Then, when moths get close to the light, they tend to turn away from the light in order to avoid it.

First, moths sense the light in their immediate vicinity and turn toward the direction where the light is greatest.

Second, moths compare the light immediately ahead of them with the light at their current position. If the ratio of 'light just ahead' to 'light here' is below a threshold value, then the moths fly forward toward the light. If the ratio of 'light just ahead' to 'light here' is above a threshold value, then moths turns away from the light. The threshold is determined by the moths' sensitivity to light.

If the moths do not detect any light, or if there simply are no lights in the space where the moths are flying, then the moths flutter about randomly.

Note that light energy is represented in this model as decreasing with the square of the distance from the light source. This characteristic is known as a "one over r-squared relationship," and is comparable to the way electrical field strength decreases with the distance from an electrical charge and the way that gravitational field strength decreases with the distance from a massive body.


Click the SETUP button to create NUMBER-LIGHTS with LUMINANCE and NUMBER-MOTHS. Click the GO button to start the simulation.

NUMBER-MOTHS: This slider determines how many lights will be created when the SETUP button is pressed.

NUMBER-LIGHTS: This slider determines how many lights will be created when the SETUP button pressed. Note that this value only affects the model at setup.

LUMINANCE: This slider influences how bright the lights will be. When a light is created, it is assigned a luminance of 20 plus a random value between 0 and LUMINANCE. Lights with a higher luminance can be sensed by moths from farther away. Note that changing LUMINANCE while the model is running has no effect.

SENSITIVITY: This slider determines how sensitive the moths are to light. When SENSITIVITY is higher, moths are able to detect a given light source from a greater distance and will turn away from the light source at a greater distance.

TURN-ANGLE: This slider determines the angle that moths turn away when they sense that the ratio of 'light ahead' to 'light here' is above their threshold value.


When the model begins, notice how moths are attracted to the two lights. What happens when the lights are created very close together? What happens when the lights are created very far apart?

Do all of the moths circle the same light? When a moth begins to circle one light, does it ever change to circling the other light? Why or why not?


Run the simulation without any lights. What can you say about the moths' flight patterns?

With the simulation stopped, use the following values: - NUMBER-LIGHTS: 1 - LUMINANCE: 1 - NUMBER-MOTHS: 10 - SENSITIVITY: 1.00 - TURN-ANGLE: 95 Notice that, at first, some moths might fly about randomly while others are attracted to the light immediately. Why?

While the model is running increase SENSITIVITY. What happens to the moths' flight patterns? See if you can create conditions in which one or more of the moths can 'escape' from its state of perpetually circling the light.

Vary the TURN-ANGLE. What happens? Why do you think the moths behave as observed with different values of TURN-ANGLE? What value or values do you think are most realistic?

It would be interesting to better understand the flight patterns of the moths in the model. Add code to the model that allows you to track the movements of one or more moths (for example, by using the pen features). Do you see a pattern? Why might such a pattern appear and how can it be altered?


This model offers only one set of rules for generating moths' circular flight around a light source. Can you think of different ways to define the rules?

Alternatively, can you imagine a way to model an earlier theory of moth behavior in which moths navigate straight lines by orienting themselves to the moon? Do rules that allow moths to navigate according to their position relative to the moon lead to the observed circling behavior around light sources that are much, much closer than the far-away moon?


This model creates a field of light across the patches, using scale-color to display the value, and the moths use face and max-one-of to traverse the light field.


Ants, Ant Lines, Fireflies, Flocking


Adams, C. (1989). Why are moths attracted to bright lights? Retrieved May 1, 2005, from


If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:


Copyright 2005 Uri Wilensky.


This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at

(back to the NetLogo Models Library)