Lattice-Walking Turtles 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 demonstrates how to create a hexagonal grid for turtles to walk around on using links.
HOW IT WORKS
In order for the hexagons along the edges of the world to connect up with the hexagons on the opposite edges in the expected way, the size of the grid must be even in both dimensions. Therefore we use a world where the origin patch (0,0) is located in the corner rather in the center, since even-dimensioned worlds have no center patch.
THINGS TO TRY
If you do:
ask walkers [ pen-down ]
Notice that the lines the walkers draw appear behind the hexagons, because the hexagons are turtles. If you want the lines to be drawn on top of the hexagons, you need to transfer the hexagons to the drawing layer and hide the hexagon turtles, like this:
ask nodes [ stamp hide-turtle ]
On the computers we tested, this also makes the model run faster since the hexagons don't need to be redrawn individually every time the view is updated. Later, if you want to clear the drawing and redraw the hexagons, do:
clear-drawing ask nodes [ stamp ]
RELATED MODELS
Link-Walking Turtles Example
Comments and Questions
breed [nodes node] breed [walkers walker] walkers-own [location] ;; holds a node to setup clear-all set-default-shape nodes "hex" ;; create a hex grid of nodes ask patches [ sprout-nodes 1 [ set color gray - 3.5 ;; dark gray set size 1.2 ;; shift even columns down if pxcor mod 2 = 0 [ set ycor ycor - 0.5 ] ] ] ;; connect the nodes to make a lattice ask nodes [ ifelse pxcor mod 2 = 0 [ create-links-with nodes-on patches at-points [[0 1] [1 0] [1 -1]] ] [ create-links-with nodes-on patches at-points [[0 1] [1 1] [1 0]] ] ] ask links [ hide-link ] ;; put some "walker" turtles on the lattice create-walkers 20 [ set color red set location one-of nodes move-to location ] reset-ticks end to go ask walkers [ set-location one-of [link-neighbors] of location ] tick end to set-location [new-location] ;; walker procedure set location new-location face new-location ;; not strictly necessary, but improves the visuals a bit move-to new-location 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 | |
---|---|---|---|---|
Lattice-Walking Turtles Example.png | preview | Preview for 'Lattice-Walking Turtles Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.