homing-particles_2009


Information

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



Procedures

NetLogo Version: NetLogo 4.0.4

;; SUMMARY
;;;;  Particles walk around each other to cluster around a home base. 
;; COPYRIGHT & LICENSE
;;;; Copyright (C) 2005 James P. Steiner
;;;; Some Rights Reserved.
;;;; Creative Commons Attribution-NonCommercial-ShareAlike License v. 2.0.
;;;; Visit http://creativecommons.org/licenses/by-nc-sa/2.0/ for more information.
;; APPLET DIMENSIONS (width x height)
;;;; 781 x 554
;;
globals
[ 
  tilt-list
]

breed [ reps ]
breed [ cons ]
breed [ clocks ]


reps-own
[ faction 
  close-enough?
]
cons-own 
[ faction
  close-enough?
  my-rep
]

to startup
   setup
end
 
to setup
  ca

  set-default-shape reps "circle"
  set-default-shape clocks "clock"

    create-clocks 1
  [ set size 10
    setxy max-pxcor - 5 max-pycor - 5
    set heading 0
    set color blue
  ]
  
   create-reps factions
   [ set faction who mod factions
     setxy 0 0
     set heading (who + .5)  * 360 / factions
     jump max-pxcor * .65
     set size max-pxcor * .1
     set color faction-color
     set label faction
  ]
   
   ask patch 0 0
   [ ask patches in-radius ( max-pxcor * .9) with [  random-float 100 < density ]
     [ sprout 1
       [ set breed cons
         set shape shape:
         set faction random factions
         set color faction-color
         set heading random 360
         set size 1.1
         set my-rep one-of reps with [ faction = [faction] of myself ]
         set close-enough? 0
       ]
     ]
   ]

   ask reps [ ask cons in-radius (size * 1.1) [ die ] ]
end

to go
   
   ask clocks [ rt 5 ]
   
   let quarter-cons .1 * count cons 
   ask reps
   [ ask (cons with [ faction = [faction] of myself ]) in-radius (size * 1.5)
     [ set close-enough? ticks 
       if shape != "X" [ set shape "X" ]
     ]
     
   ]
   ask cons
   [ if close-enough? != ticks
     [ set heading towards-nowrap my-rep
       let tn tilt-neighbors with [ not (any? cons-here )]
       ifelse any? tn 
       [ let target min-one-of tn [ distance-nowrap [my-rep] of myself ]
         set heading towards-nowrap target
         setxy [pxcor] of target [pycor] of target
         set color faction-color
         set close-enough? 0
         if shape != shape: [ set shape shape: ]

       ]
       [ if color mod 10 < 8.5 [ set color color + .25 ]
       ]
     ]
   ]
   every .1
   [ if mouse-down?
     [ ask patch mouse-xcor mouse-ycor [ ask cons in-radius 5 [ die ] ] ]
   ]
   tick
end



to-report tilt-neighbors-3
    report patches at-points
    (list (list (dx) (dy) )
          (list (sin (heading + 45)) (cos (heading + 45)))
          (list (sin (heading - 45)) (cos (heading - 45)))
     )
end

to-report tilt-neighbors
    let t []
    if    ++0 [set t lput (list dx dy) t]
    if   ++45 [set t lput (list (sin (heading +  45)) (cos (heading +  45))) t ]
    if   --45 [set t lput (list (sin (heading -  45)) (cos (heading -  45))) t ]
    if   ++90 [set t lput (list (sin (heading -  90)) (cos (heading -  90))) t   ]      
    if   --90 [set t lput (list (sin (heading +  90)) (cos (heading +  90))) t    ]    
    if  ++135 [set t lput (list (sin (heading + 135)) (cos (heading + 135))) t     ]    
    if  --135 [set t lput (list (sin (heading - 135)) (cos (heading - 135))) t      ]   
    if +/-180 [set t lput (list (sin (heading + 180)) (cos (heading + 180))) t       ] 

    report (patches at-points t) 
end

to lottery [ chance ]
   ask reps
   [ if random 100 < chance
       [ let r one-of reps with [ self != myself]
         let p1 patch-here
         let p2 [ patch-here ] of r
         setxy [pxcor] of p2 [pycor] of p2
         ask r
         [ setxy [pxcor] of p1 [pycor] of p1 
         ]
       ]
   ]
 end


to-report faction-color
   report red + faction * 30
end

                    


Download Link

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