Hex Cell Aggregation

Hex Cell Aggregation preview image

3 collaborators

Uri_dolphin3 Uri Wilensky (Author)
79107734_n00-1 Seth Tisue (Author)
Josh3 Josh Unterman (Author)

Tags

computer science 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 526 times • Downloaded 81 times • Run 2 times
Download the 'Hex Cell Aggregation' 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 model of growth. It takes place on a two-dimensional hexagonal grid of cells. Cells can either be alive or dead. Various growth patterns result, depending on the exact rules governing growth.

HOW IT WORKS

SETUP arranges cells in a hexagonal grid, as in Hex Cells Example. The edges of the grid do not wrap.

Only the center cell is alive at the start.

The switches determine which dead cells are eligible to become alive. For example, if the ONE-NEIGHBOR? switch is on, dead cells that have exactly one alive neighbor are eligible for growth, and so on for the rest of the switches.

Each tick, one eligible dead cell goes live.

Dead cells are invisible (black). Live cells are shown in orange or red depending on whether they have any dead neighbors.

HOW TO USE IT

SETUP places one alive cell in the middle of the grid.

GO advances the growth process.

X-NEIGHBORS? are switches that, when on, allow new cells to grow where they will have X alive neighbors. X ranges from one to six because the cells are on a hexagonal grid and so each cell has 6 neighbors.

READ-SWITCHES makes your settings for the switches take effect. (They don't take effect right away because the model is coded in a special way in order to run faster.)

THINGS TO NOTICE

When some switches are turned off, "holes" appear in the pattern. Depending on which X-NEIGHBORS? switches are on and which are off, those holes can be different shapes. Some interesting configurations are {1, 2, 4} (ONE-NEIGHBOR?, TWO-NEIGHBORS?, AND FOUR-NEIGHBORS? on while all other switches are off), {1}, {1, 4, 5}, {1, 3, 5, 6}, and {1, 3, 4, 5, 6}.

Often, as the alive cells approach the border, the overall shape resembles a circle.

For different configurations of the X-NEIGHBORS? switches, the "Cell Types" plot shows very different numbers of alive, dead, and inner-edge cells when the model stops.

THINGS TO TRY

Change the size of the world. If it's much bigger, the model might run too slowly. If it's smaller, can you get different patterns?

Switch off TWO-NEIGHBORS? for a run. Does the overall shape look any different? After the model has been running for a while, change the switches to not allow 1 or 2 neighbors while allowing for 3 and up. (Don't forget to press the CHANGE-SWITCHES button.) Watch it go. What happens if you then change it to allow only for 1 or 2?

EXTENDING THE MODEL

Implement the model on a regular square grid using both neighbors4 and neighbors instead of the neighbors6 we used in this model. Figure out a way to measure how quickly the alive cells spread to the edge in different configurations.

To better see the near-circular shape of the aggregation as the growth gets near the edge, add a check that stops the model when a cell on the edge becomes alive.

Add a plot that tracks the ratio of orange to red cells.

Each tick one eligible dead cell goes live. This one-at-a-time update rule differs from many cell-based models which update all the cells at once. (This update rule is specified in the reference in the CREDITS AND REFERENCES section.) Change the rules so that each tick, all of the eligible dead cells go live. What different result do you observe, if any?

NETLOGO FEATURES

The code uses lists in order to make the model run faster. The code would be considerably simpler if these lists weren't used, but it would also run much slower. See the comments in the Code tab for details on the use of lists in this model.

RELATED MODELS

Diffusion Limited Aggregation
Life
Hex Cells Example

CREDITS AND REFERENCES

This model was inspired by Stephen Wolfram's A New Kind of Science. A very similar model is discussed here: http://www.wolframscience.com/nksonline/page-331?firstview=1. In the notes at the end of the book, many extensions are suggested, although none on a hexagonal grid.

Thanks to Josh Unterman and Seth Tisue for their work on this model.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

COPYRIGHT AND LICENSE

Copyright 2007 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

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

Click to Run Model

globals [
  ;; This list contains the numbers of the switches that are on,
  ;; for example, if all six switches are on, the list will be
  ;; [1 2 3 4 5 6].  The list is only built during SETUP and
  ;; READ-SWITCHES.
  switches
  ;; This is a list of cells which are eligible to become alive.
  eligibles
]

;; About the use of lists in this model:
;;
;; The model could be coded more simply without the "switches" and
;; "eligibles" lists.  But using those lists enables the model to run
;; much faster.
;;
;; The "switches" list is used so a cell can quickly check its live
;; neighbors count against the six switches without having to actually
;; inspect the switches one by one.  If the user flips a switch,
;; the list will be out of date, which is why we ask the user to
;; press the SETUP or READ-SWITCHES buttons after changing switches.
;;
;; The "eligibles" list is used so that when we are trying to decide
;; what cell will become alive next, we don't have to check every
;; cell.  The list contains only those cells we know are eligible.
;; Every time a cell becomes alive, we remove it from the list.
;; We must also check that cell's neighbors to see if they need
;; to be added or removed from the list.

breed [cells cell]

cells-own [
  hex-neighbors
  live-neighbor-count
  eligible?
]

to setup
  clear-all
  setup-grid
  read-switches
  ;; start with one live cell in the middle
  ask cells-on patch 0 0 [ become-alive ]
  reset-ticks
end 

to go
  if empty? eligibles [ stop ]
  ask one-of eligibles [ become-alive ]
  tick
end 

to become-alive  ;; cell procedure
  show-turtle
  set eligible? false
  set eligibles remove self eligibles
  ask hex-neighbors [
    set live-neighbor-count live-neighbor-count + 1
    if live-neighbor-count = 6 [ set color red ]
    update-eligibility
  ]
end 

to update-eligibility  ;; cell procedure
  ifelse eligible?
  ;; case 1: currently eligible
  [
    if not member? live-neighbor-count switches [
      set eligible? false
      set eligibles remove self eligibles
    ]
  ]
  ;; case 2: not currently eligible
  [
    ;; the check for hidden? ensures the cell isn't already alive
    if hidden? and member? live-neighbor-count switches [
      set eligible? true
      ;; The order of the list doesn't matter, but in NetLogo
      ;; (as in Logo and Lisp generally), FPUT is much much
      ;; faster than LPUT.
      set eligibles fput self eligibles
    ]
  ]
end 

;;; only allow the new alive cells to have number of neighbors as allowed by the switches

to read-switches
  set switches []
  if one-neighbor?    [ set switches lput 1 switches ]
  if two-neighbors?   [ set switches lput 2 switches ]
  if three-neighbors? [ set switches lput 3 switches ]
  if four-neighbors?  [ set switches lput 4 switches ]
  if five-neighbors?  [ set switches lput 5 switches ]
  if six-neighbors?   [ set switches lput 6 switches ]
  ask cells [
    set eligible? hidden? and member? live-neighbor-count switches
  ]
  set eligibles [self] of cells with [eligible?]
end 

;;; this was mostly taken from Hex Cells Example

to setup-grid
  set-default-shape turtles "hex"
  ask patches [
    sprout-cells 1 [
      hide-turtle
      set color orange
      set eligible? false
      if pxcor mod 2 = 0 [
        set ycor ycor - 0.5
      ]
    ]
  ]
  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 


; Copyright 2007 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
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 Hex Cell Aggregation Download this version

Attached files

File Type Description Last updated
Hex Cell Aggregation.png preview Preview for 'Hex Cell Aggregation' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.