in-radius

 

in-radius is a primitive that reports all the agents within a certain radius of the current agent. For example, a turtle might like to know how many other turtles are within a radius of two units of itself or a patch might like to know how many turtles are within three units of itself.

ask turtles [
    if any? other turtles in-radius 2 [
        create-link-with one-of other turtles in-radius 2
    ]
]

Things to keep in mind when using in-radius:

In the model example below, we have an environment represented with green patches and a factory at the center. When the go button is clicked, the factory pollutes all the patches within a radius of 5, represented by darker green patches.

 

Try it Yourself