Link Lattice Example
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This example shows how to construct a regular lattice or mesh of links. Two kinds of lattice are demonstrated, a square lattice (where each node has four neighbors) and a hex lattice (where each node has six neighbors).
THINGS TO TRY
The current code creates undirected links. To modify setup-square
to create a fully connected lattice of directed links, use create-links-to
instead of create-links-with
. (Making the same change to the hex lattice code is only a little trickier.)
If you turn off wrapping at one or both world boundaries, the lattice will be bounded. You don't need to change the square lattice code in that case, because the neighbors4
primitive returns fewer than four neighbors for patches on the world edges. (Making the same change to the hex lattice code is only a little trickier.)
The square lattice can be modified to include diagonal links by changing neighbors4
to neighbors
.
RELATED MODELS
- Hex Cells Example: shows how to treat patches as a hexagonal lattice, without creating any links.
- Lattice-Walking Turtles Example: shows how to make turtles walk along the lattice.
Comments and Questions
to setup-square clear-all ;; Create a turtle on each patch. A link always connects two ;; turtles, so we must make turtles first before we can make ;; links. ask patches [ sprout 1 ] ;; Now create the links. Note that some turtles will try to create ;; links that already exist because they were made by earlier ;; turtles. That's OK; the CREATE-LINKS-WITH command will skip ;; links that already exist. ask turtles [ create-links-with turtles-on neighbors4 ] end to setup-hex clear-all ;; Create a turtle on each patch. A link always connects two ;; turtles, so we must make turtles first before we can make ;; links. ask patches [ sprout 1 ] ;; Now create the links. ask turtles [ create-links-with turtles-at 0 1 create-links-with turtles-at 1 0 if pxcor mod 2 = 0 [ create-links-with turtles-at 1 -1 create-links-with turtles-at -1 -1 ;; Move every other column of turtles down by half a patch, ;; resulting in a hexagonal pattern. set ycor ycor - 0.5 ] ] 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.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Link Lattice Example.png | preview | Preview for 'Link Lattice Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.