Hex Cells Example

Hex Cells Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 606 times • Downloaded 66 times • Run 1 time
Download the 'Hex Cells 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.)


Comments and Questions

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

Click to Run Model

breed [ cells cell ]

cells-own [
  hex-neighbors  ;; agentset of 6 neighboring cells
  n              ;; used to store a count of white neighbors
]

to setup1
  clear-all
  setup-grid
  ;; make the center hexagon white, as the "seed" from which we
  ;; grow our "snowflake"
  ask patch 0 0
    [ ask cells-here
        [ set color white ] ]
  reset-ticks
end 

to setup2
  clear-all
  setup-grid
  ;; make two center hexagons white, as the "seed" from which we
  ;; grow our "snowflake"
  ask patches at-points [[0 0] [1 0]]
    [ ask cells-here
        [ set color white ] ]
  reset-ticks
end 

to setup-grid
  set-default-shape cells "hex"
  ask patches
    [ sprout-cells 1
        [ set color gray - 3  ;; dark gray
          ;; shift even columns down
          if pxcor mod 2 = 0
            [ set ycor ycor - 0.5 ] ] ]
  ;; now set up the hex-neighbors agentsets
  ask cells
    [ ifelse pxcor mod 2 = 0
        [ set hex-neighbors cells-on patches at-points [[0 1] [1 0] [1 -1] [0 -1] [-1 -1] [-1 0]] ]
        [ set hex-neighbors cells-on patches at-points [[0 1] [1 1] [1  0] [0 -1] [-1  0] [-1 1]] ] ]
end 

to go
  ;; these are example cellular automaton rules; they produce
  ;; a snowflake-like pattern
  ask cells
    [ set n count hex-neighbors with [color = white] ]
  ask cells
    [ if n = 1
        [ set color white ] ]
  tick
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 almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Hex Cells Example Download this version
Uri Wilensky almost 14 years ago Hex Cells Example Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.