Hex Cells Example
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 make a model that uses a hexagonal grid of cells.
The cellular automaton rules used produce a snowflake-like pattern.
HOW IT WORKS
Since patches are square, we must represent the cells as turtles instead.
Each patch sprouts a "cell" turtle. 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 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 you don't try to use primitives such as distance
and towards
.
Also, you must use the hex-neighbors
variable instead of the built-in neighbors
and neighbors4
reporters.
RELATED MODELS
This example is for stationary cells. Hex Turtles Example shows how to make turtles that move along a hexagonal lattice. (It would also be possible to combine both techniques in a single model.)
Link Lattice Example and Lattice-Walking Turtles Example demonstrate another approach to making a hexagonal lattice, using links instead of just patches.
Comments and Questions
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.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Hex Cells Example.png | preview | Preview for 'Hex Cells Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.