NetLogo version NetLogo 3.1.1
Running with NetLogoLite.jar version 314.
NetLogo Version: NetLogo 3.1.1
;; SUMMARY ;;;; A model where particles follow other particles, like a tail ;; COPYRIGHT & LICENSE ;;;; Copyright (C) 2003 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. ;; UPDATED to use NetLogo 3.1.1, Nov. 2006 Globals [ leader followers time old-pop] turtles-own [my-leader order] To setup clear-all ask patches [set pcolor back-color ] set old-pop population Create-custom-turtles population [ set shape select-shape set size 1.01 ;; disable use of pre-calculated shape, prevent clipping of shape! ] designate-leader designate-followers color-tail repeat 5 [ activate-tail ] end to designate-leader Set leader turtle 0 ask leader [ set color yellow setxy 0 0 set heading 5 set order 0 ] end to designate-followers Set followers sort (turtles with [who != who-of leader]) foreach followers [ ask ? [ set my-leader max-one-of turtles with [who < who-of myself] [who] set order (order-of my-leader) + 1 ]] end to color-tail foreach followers [ ask ? [ set color scale-color tail-color order (population * 1.2) (population * -.2) ]] end to move-head Ask leader ;; make leader loop about the universe [ if vary-turn? or vary-spd? [ set time time + frequency ] if turn? [ if vary-turn? [ set steering (sin time) ] rt steering * max-steer ] if move? [ ifelse vary-spd? [ jump speed * abs(cos (time * 1.1)) ] [ jump speed ] ] ] end to move-tail foreach sort followers [ Ask ? ;; follow each other [ ;; point to leader face my-leader ;; step towards leader. jump (distance my-leader) * tightness ;; turn to an angle somewhere between leader's heading and the heading I took to get here. set heading ratio-heading heading (heading-of my-leader) stiffness ;; take a step back (e.g. to the "connection point" of the leader) jump (- spacing * tightness) ] ] end ;; monitors the population slider for changes, and ;; dynamicly changes the tail length when needed to check-pop if population != old-pop [ ifelse population < old-pop [ foreach n-of (old-pop - population ) followers [ ask ? [ die ] ] ] [ ask last followers [ hatch population - old-pop [ ]] ] designate-followers color-tail set old-pop population ] end ;; monitors tail-color slider to check-color if not (shade-of? (color-of turtle 1) tail-color) [ color-tail ] if (pcolor-of patch 0 0) != back-color [ ask patches [ set pcolor back-color ] ] end to activate-tail every delay [ check-pop check-color move-head move-tail ] end to-report average-heading [a b] ; reports the simple average of two headings report atan ( .5 * ( (sin a) + (sin b) ) ) ( .5 * ( (cos a) + (cos b) ) ) end to-report ratio-heading [a b ratio] ; reports the weighted average of two headings let xx ( (sin a) * (1 - ratio) + (sin b) * (ratio) ) let yy ( (cos a) * (1 - ratio) + (cos b) * (ratio) ) ifelse xx != 0 or yy != 0 [ report atan xx yy ] [ report 0 ] end
View or download the complete model file (to download: right-click, save-link-as):
-- Download tail-model_2006 --