# Neighborhoods Example

### 1 collaborator

Uri Wilensky (Author)

### Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 947 times • Downloaded 34 times • Run 5 times

## Comments and Questions

Click to Run Model

```;;  This procedure creates 8 turtles in puts them in a circle,
;;  and moves three to the edges of the world

to setup
ca
crt 8
[ fd 10 ]
ask turtle 0 [ fd 7 ]
ask turtle 1 [ fd 14 ]
ask turtle 2 [ fd 7 ]
end

;;  This procedure colors all the patches neighboring each turtle.
;;  neighbors reports the eight patches surrounding the turtle.
;;  Note that patches have neighbors as well, and can also use the neighbors reporter.

to paint-neighbors
clear-patches
[ paint-agents neighbors ]
end

;;  This procedure is similar to paint-neighbors, but uses the neighbors4 reporter.
;;  neighbors4 reports only the four patches adjacent to the current patch, and does not include
;;  the four neighbors which are only diagonally touching the current patch.
;;  As with neighbors, both turtles and patches can use neighbors4.

to paint-neighbors4
clear-patches
[ paint-agents neighbors4 ]
end

;;  This procedure uses in-radius to paint a "circle" around each turtle.
;;  "agentset in-radius n" reports those agents in agentset whose distance from the current agent
;;  is less than or equal to n. For patches, distance is measured from the center of the patch.
;;  Note that the caller can be a turtle or a patch, and agentset can be a set of turtles or a set of
;;  patches, so you can also use in-radius to locate turtles within a given radius
;;  of another turtle or patch.  Also notice that the reported agentset includes the patch that the
;;  turtle is currently on.

clear-patches
end

;;  This procedure uses the at-points reporter to paint an arbitrary neighborhood.
;;  at-points lets you specify groups of agents on individual patches, using points
;;  relative to the calling agent (so [0 0] indicates the patch the agent is on).
;;  As with the above primitives, at-points can be used by both turtles and patches.

to paint-at-points
clear-patches
[
if points = "corners"
[ paint-agents patches at-points [[1 1] [-1 1] [-1 -1] [1 -1 ]] ]
if points = "left"
[ paint-agents patches at-points [[-1 1] [-1 0] [-1 -1]] ]
if points = "L-shape"
[ paint-agents patches at-points [[-1 1] [-1 0] [-1 -1] [0 -1] [1 -1 ]] ]
if points = "line-up"
[ paint-agents patches at-points [[0 1] [0 2] [0 3] [0 4]] ]
]
end

;; This is a helper procedure, used to set the color of a set of patches.

to paint-agents [agents]
ask agents [ set pcolor [color] of myself - 2 ]
end

; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.
```

There are 10 versions of this model.

Uri Wilensky over 9 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 10 years ago Updated version tag Download this version
Uri Wilensky about 11 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 12 years ago Neighborhoods Example Download this version
Uri Wilensky over 12 years ago Neighborhoods Example Download this version

## Attached files

File Type Description Last updated
Neighborhoods Example.png preview Preview for 'Neighborhoods Example' almost 10 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.