Hex Turtles Example

Hex Turtles Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner over 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 752 times • Downloaded 166 times • Run 0 times
Download the 'Hex Turtles Example' 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 demonstrates how to have turtles move on a hexagonal lattice instead of NetLogo's usual square lattice.

Note that this technique only works as long as the turtles always stay on the vertices of the lattice.

HOW IT WORKS

We treat the square lattice of patches as if it were a hex lattice, as follows:

  • A turtle's heading must always be a multiple of 60.

  • Turtles on even patch columns are offset down by half a patch. (Since the south boundary of a patch is part of the patch, this does not move the turtle to a different patch.)

  • The world must be an even size grid otherwise a bit of extra math in the hex-fd procedure is needed to deal with two even or two odd columns in a row around the edges (if wrapping is turned on).

The resulting lattice has the correct structure, but distances and angles are distorted. So the hexagons aren't actually regular, but it doesn't matter as long as the turtles move not using the built in fd command but using the hex-fd procedure, and as long as you don't try to use primitives such as distance and towards.

RELATED MODELS

This example is for moving turtles. Hex Cells Example shows how to make stationary hexagonal cells, such as for a cellular automaton. (It would also be possible to combine both techniques in a single model.)

Comments and Questions

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

Click to Run Model

to setup
  clear-all
  set-default-shape turtles "arrow half"
  crt 500
    [ move-to one-of patches
      ;; turtle headings must be multiples of 60
      set heading 60 * random 6
      ;; shift even columns down
      if pxcor mod 2 = 0
        [ set ycor ycor - 0.5 ] ]
  reset-ticks
end 

to go
  ;; turtles do a random walk (usually going straight,
  ;; occasionally turning)
  ask turtles
    [ hex-fd
      rt one-of [-60 0 0 0 0 0 60] ]
  tick
end 

to hex-fd  ;; turtle procedure
   ;; the world must be an even size grid so that when the turtles wrap
   ;; there are not two even or two odd columns in a row.
   setxy (xcor + item (heading / 60) [0 1 1 0 -1 -1])
         (ycor + item (heading / 60) [1 0.5 -0.5 -1 -0.5 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.

Uploaded by When Description Download
Uri Wilensky over 12 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky almost 13 years ago Updated version tag Download this version
Uri Wilensky over 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky about 15 years ago Model from NetLogo distribution Download this version
Uri Wilensky about 15 years ago Hex Turtles Example Download this version
Uri Wilensky about 15 years ago Hex Turtles Example Download this version

Attached files

File Type Description Last updated
Hex Turtles Example.png preview Preview for 'Hex Turtles Example' over 12 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.