Ora

What is Sprout in NetLogo?

Published in NetLogo Primitive 4 mins read

In NetLogo, sprout is a fundamental patch-only primitive that allows patches to create new turtles directly on themselves. It's a powerful command primarily used when you want the environment (patches) to initiate the creation of agents, such as for population growth, seeding, or initializing models where objects appear from specific locations.

Understanding the sprout Command

sprout is unique because it must always be used within the context of an ask patches [...] block. This ensures that the command is executed by individual patches, each potentially creating one or more new turtles at its own location.

  • Patch-Exclusive: Only patches can execute the sprout command. You cannot sprout from a turtle or the observer directly.
  • Turtle Creation: When a patch sprouts, it creates new turtles on its own coordinates (xcor, ycor).
  • Initial Properties: Newly sprouted turtles automatically inherit their xcor and ycor from the patch that created them. By default, they are white and have a random heading. You can easily set their other properties immediately after creation.

How sprout Works and Its Syntax

The sprout command offers flexibility, allowing you to specify how many turtles a patch should create and to assign initial properties to these new turtles.

Basic Syntax

The simplest form of sprout creates one new turtle on the executing patch.

Creating Multiple Turtles

You can specify the number of turtles a patch should sprout.

This example tells the patch at (0,0) to create five new red circle turtles on itself.

Setting Initial Turtle Properties

Within the square brackets [...] following sprout, you can define properties for the newly created turtles. This is crucial for giving your agents distinct characteristics from the moment they are born.

Key Characteristics of sprout

Feature Description
Agent Type A primitive specifically for patches.
Action Creates new turtles.
Location New turtles are created directly on the sprouting patch's coordinates.
Context Must be called within an ask patches [...] block or by a patch itself (e.g., to go ask one-of patches [ sprout 1 ]).
Default State New turtles are white, have a random heading, and are positioned at the creating patch's xcor and ycor.
Primary Use Ideal for initializing environments with agents, simulating birth/reproduction tied to specific locations, or dynamic population growth based on environmental conditions.

Practical Applications and Examples

sprout is incredibly versatile for various modeling scenarios:

  • Initial Population Seeding: To quickly populate your world with agents at the start of a simulation.
  • Resource Generation: Imagine patches that represent fertile ground, continuously sprouting "food" turtles.
  • Reproduction and Growth: When a "mother" patch (or a patch containing a "mother" agent) is responsible for creating new offspring.

Why Use sprout Instead of create-turtles?

While create-turtles can also create new turtles, sprout is distinct because it always ties the creation to a specific patch.

  • create-turtles: Creates turtles from the perspective of the observer (or a turtle), typically at (0,0) by default, and then you have to move them. It's more about global creation.
  • sprout: Creates turtles from the perspective of the patch itself, directly at that patch's location. This makes it ideal for localized creation events where the environment's state dictates where and what new agents appear.

By understanding and utilizing sprout, you can build more complex and spatially-aware NetLogo models where the environment plays an active role in shaping the agent population. For more details, you can refer to the NetLogo Dictionary.