I place a set of agents in a rectangular grid.

Begin micro-behaviour


Begin NetLogo code:
substitute-text-area-for upper-left-x min-pxcor                       
substitute-text-area-for upper-left-y min-pycor                       
substitute-text-area-for grid-width world-width                     
substitute-text-area-for grid-height world-height                       
substitute-text-area-for selection-criteria true                
  all-individuals with [selection-criteria] 
  upper-left-x  ; upper left x
  upper-left-y  ; upper left y
  grid-width    ; width
  grid-height   ; height
End NetLogo code


To change the location of the grid of agents change the upper left x and y. To make a grid of a different size edit the width and height. If you want separate rectangles for different kinds of agents, e.g. "Sheep" then replace true with kind = "Sheep" inside the square brackets.

Related Micro-behaviours

LAYOUT-CIRCLE lays out agents in a circle. LAYOUT-SPRING computes a layout treating the links as springs.

SET-RANDOM-POSITION sets an agent's heading to a random value. SET-RANDOM-UNOCCUPIED-POSITION also finds a random position but only if it is unoccupied.

How this works

This uses the Modelling4All NetLogo layout-grid command to place the agents in a rectangle.


This was implemented by Ken Kahn on 10 November 2009.