NetLogo version NetLogo 3.0.2
Running with NetLogoLite.jar version 302.
NetLogo Version: NetLogo 3.0.2
;; 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. 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-turtles population 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 turtles with [who != who-of leader] ask followers [ set my-leader max-one-of turtles with [who < who-of myself] [who] set order (order-of my-leader) + 1 ] end to color-tail ask followers [ 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? [ fd speed * abs(cos (time * 1.1)) ] [ fd speed ] ] ] end to move-tail Ask followers ;; follow each other [ without-interruption [ ;; point to leader face my-leader ;; step towards leader. fd (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) bk spacing * tightness ] ] end ;; monitors the population slider for changes, and ;; dynamicly changes the tail length when needed to check-pop if population != old-pop [ while [ count turtles > population ] [ ask max-one-of turtles [who] [ die ] ] while [ count turtles < population ] [ create-turtles 1 ] 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 report atan ( (sin a) * (1 - ratio) + (sin b) * (ratio) ) ( (cos a) * (1 - ratio) + (cos b) * (ratio) ) end
View or download the complete model file (to download: right-click, save-link-as):
-- Download tail-model --