create-linked-groups


Information

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


WHAT IS IT?


-------
A model to demonstrate a technique of creating circular groups of turtles, also arranged in a circle.

Procedures

NetLogo Version: NetLogo 4.0.4

  
          
          
to setup
   ca
   
   let num-groups num
   let group-pop floor (num / 2)
   let group-index 0
   let group-slice-angle 360 / (num-groups )
   let unit-slice-angle 360 / group-pop
   ;; use some geometry to figure out the spacing for the rings of turtles
   let unit-radius  group-pop / (pi * 2)
   let margin 2 ;; since the units are non-zero widths, this keeps the groups from overlapping
   let group-radius (2 * unit-radius * num-groups + margin) / (pi * 2)
   
   set-default-shape turtles "circle"
   repeat num-groups
   [ let unit-index 0
     let first-one nobody
     let last-one nobody
     ;; create this group's turtles
     create-turtles group-pop
     [ ;; using the indexes, calculate the group angle and individual angle 
       ;; face toward where the group center will be
       set heading group-index * group-slice-angle
       ;; jump to the group center
       jump group-radius 
       jump unit-radius
       ;; face away from the group center
       set heading unit-index * unit-slice-angle
       ;; jump away from the center
       jump unit-radius
       ;; make unit face the center of the group
       rt 180

       ;; use the group index number to color the group
       set color group-index * 10 + 3 + 2 * floor (group-index / 14 )
       __set-line-thickness .2
       ;; just because i can
       
       ;; create link to previous agent in this group (unless first)
       if first-one = nobody [ set first-one self ]
       if last-one != nobody [ create-link-with last-one  [ set thickness .2 set color white]]
       set last-one self
       
       ;; increment the unit index
       set unit-index unit-index + 1

     ]
     ;; first agent in group creates link with last-created agent
     ask first-one [ create-link-with last-one [ set thickness .2 set color white]]
     
     ;; increment the group index number
     set group-index group-index + 1
   ]
end       

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download create-linked-groups --