Neighborhoods Example 3D

Neighborhoods Example 3D preview image

1 collaborator

Uri_dolphin3 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 3D 4.1pre7 • Viewed 293 times • Downloaded 37 times • Run 0 times
Download the 'Neighborhoods Example 3D' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

This is a 3D version of the 2D model Neighborhoods Example This code example shows how to use the basic 2D and 3D neighborhood primitives in a 3D world. These include neighbors, neighbors6, in-radius, and at-points:

- neighbors: reports the 26 patches surrounding a patch or turtle

- neighbors6: reports the same patches3d, excluding the ones at the corners

- in-radius : reports those agents in agentset whose distance from the caller is less than or equal to n.

- at-points : reports those agents in agentset at the given points relative to the caller, where list is a list of two-element lists.

Although in this example, we only change the color of the reported patches, you can of course do more complicated operations, including assigning that agentset to a variable. This is particularly useful for Cellular Automata models.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;  This procedure creates 8 turtles in puts them in a circle

to setup
  ca
  setxyz 10 -20 6 ; set the observer position
  crt 8
    [ fd 9 ]
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
  ask turtles
    [ 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-neighbors6
  clear-patches
  ask turtles
    [ paint-agents neighbors6 ]
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.

to paint-in-radius
  clear-patches
  ask turtles
    [ paint-agents patches in-radius radius ]
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
  ask turtles
  [
    if points = "corners"
      [ paint-agents patches at-points
        [ [1 1 1] [-1 1 1] [-1 -1 1] [1 -1 1]
          [1 1 -1] [-1 1 -1] [-1 -1 -1] [1 -1 -1]] ]
  ]
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 


; Copyright 2004 Uri Wilensky. This code may be freely copied, distributed,
; altered, or otherwise used by anyone for any legal purpose.

There are 3 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Neighborhoods Example 3D Download this version

Attached files

File Type Description Last updated
Neighborhoods Example 3D.png preview Preview for 'Neighborhoods Example 3D' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.