island-generator


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT?


-------
A model to demonstrate a method of generating "random" shaped islands "randomly" placed on the sea.

Procedures

NetLogo Version: NetLogo 4.0.4

globals
[ sea-color
  land-color
  colony-color

  isle-size
  isle-spacing
]

patches-own
[ my-island 
]

to setup
   ca
   setup-constants
   setup-islands
   mutate-coastlines
end

to setup-constants
    set sea-color sky ;; I know, funny.
    set land-color brown
    set colony-color green

   set isle-size 5 ;; used as a radius, here.
   set isle-spacing 20 ;; center to center, not edge to edge.
   ;; alternately, you can define the *number* of islands you want,
   ;; then calculate the spacing and size, based on the world-size.
end

to setup-islands
   ask patches
   [ set pcolor sea-color
     set my-island nobody
   ]

   ;; the maximum island shift allowed to ensure no islands overlap
   let max-shift .66 * ( isle-spacing - 2 * isle-size ) 
   let isle-centers patches with
   [ (pxcor mod isle-spacing) = 0 and (pycor mod isle-spacing) = 0
     ; and not too close to edge
     and max-pxcor - (abs pxcor) > isle-spacing
     and max-pycor - (abs pycor) > isle-spacing
   ]
   
   ask isle-centers
   [ let shift-x (random (2 * max-shift) - max-shift)
     let shift-y (random (2 * max-shift) - max-shift)
     let new-center patch-at shift-x shift-y
     let isle-id new-center
     ask new-center
     [ 
     ask patches in-radius isle-size
     [ set pcolor land-color
       set my-island isle-id
     ]
     ]
   ]
end

to mutate-coastlines
    ;; select the coastline patches, and make them grow or shrink randomly
    repeat (world-width * 2)
    [ let coasts (patches with [ pcolor = land-color and any? (neighbors with [ pcolor = sea-color ]) and count neighbors with [ pcolor = land-color ] >= 3])
      if any? coasts
      [ ask one-of coasts
        [ let isle-id  my-island
          ;; grow or shrink
          ifelse random 2 = 0
          [ ;; grow
            ask one-of neighbors with [ pcolor = sea-color ]
            [ ask patches in-radius 2
              [ set pcolor land-color
                set my-island isle-id
              ]
            ]
          ]
          [ ;; shrink
            ask one-of neighbors with [ pcolor = sea-color ]
            [ ask patches in-radius 2
              [ set pcolor sea-color
                set my-island nobody
              ]
            ]
          ]
        ]
      ]
      
      ;; comment out the display if used in production code--it slows things down a lot!
      every .5 [ display ]
      
    ]
    ;; finally, take action to prevent touching islands
    ask patches with 
    [ my-island != nobody
      and
      any? neighbors with [ my-island != nobody and my-island != [ my-island ] of myself ]
    ]
    [ set my-island nobody
      set pcolor sea-color
    ]
end

    

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download island-generator --