turtles-own [ leader ;; the id number of the turtle this turtle is following, ;; or nobody if not following follower ;; the id number of the turtle that is following this turtle, ;; or nobody if not being followed ] to setup ca cct numturtles [ set color pink setxy (random-float screen-size-x) (random-float screen-size-y) set leader nobody set follower nobody ] setup-plot plot-turtles end to go ask turtles [ if leader = nobody [ attach-turtle ] move-turtle ] plot-turtles end to attach-turtle ;; turtle procedure locals [other xd yd] ;; find a random patch to test inside the donut set xd near-radius + random (far-radius - near-radius) set yd near-radius + random (far-radius - near-radius) if random 2 = 0 [ set xd (- xd) ] if random 2 = 0 [ set yd (- yd) ] ;; check for free turtles on that patch set other random-one-of (turtles-at xd yd) with [follower = nobody] ;; if we didn't find a suitable turtle, stop if (other = nobody) [ stop ] ;; we're all set, so latch on! set follower-of other who set leader other ;; change our color ifelse follower = nobody [ set color lime ] [ set color sky set shape "body" ] ;; change our leader's color ifelse leader-of other = nobody [ set color-of other yellow ] [ set color-of other sky set shape-of other "body" ] end to move-turtle ;; turtle procedure ;; if we are still unattached... ifelse leader = nobody ;; do a somewhat random glide [ rt random-float waver - random-float waver ] ;; otherwise follow the leader [ set heading towards leader ] fd 1 end to setup-plot set-current-plot "Turtle Count" set-plot-y-range 0 numturtles end to plot-turtles if not plot? [ stop ] set-current-plot-pen "unattached" plot count turtles with [color = pink] set-current-plot-pen "heads" plot count turtles with [color = yellow] set-current-plot-pen "bodies" plot count turtles with [color = sky] set-current-plot-pen "tails" plot count turtles with [color = lime] end ; *** NetLogo Model Copyright Notice *** ; ; This model was created as part of the project: CONNECTED MATHEMATICS: ; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL ; MODELS (OBPML). The project gratefully acknowledges the support of the ; National Science Foundation (Applications of Advanced Technologies ; Program) -- grant numbers RED #9552950 and REC #9632612. ; ; Copyright 1998 by Uri Wilensky. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from Uri Wilensky. ; Contact Uri Wilensky for appropriate licenses for redistribution for ; profit. ; ; This model was converted to NetLogo as part of the project: ; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN ; CLASSROOMS. The project gratefully acknowledges the support of the ; National Science Foundation (REPP program) -- grant number REC #9814682. ; Converted from StarLogoT to NetLogo, 2001. Updated 2002. ; ; To refer to this model in academic publications, please use: ; Wilensky, U. (1998). NetLogo Follower model. ; http://ccl.northwestern.edu/netlogo/models/Follower. ; Center for Connected Learning and Computer-Based Modeling, ; Northwestern University, Evanston, IL. ; ; In other publications, please use: ; Copyright 1998 by Uri Wilensky. All rights reserved. See ; http://ccl.northwestern.edu/netlogo/models/Follower ; for terms of use. ; ; *** End of NetLogo Model Copyright Notice *** @#$#@#$#@ GRAPHICS-WINDOW 310 10 689 410 20 20 9.0 1 10 1 1 1 CC-WINDOW 310 412 679 526 Command Center BUTTON 149 42 236 75 go go T 1 T OBSERVER T BUTTON 53 42 138 75 setup setup NIL 1 T OBSERVER T SLIDER 72 190 222 223 waver waver 0.0 359.0 70.0 1.0 1 NIL SLIDER 72 155 222 188 far-radius far-radius 0.0 50.0 10.0 1.0 1 NIL SLIDER 51 79 239 112 numturtles numturtles 0 1000 350 10 1 NIL SLIDER 72 120 222 153 near-radius near-radius 0.0 50.0 5.0 1.0 1 NIL PLOT 13 301 301 463 Turtle Count time # 0.0 100.0 0.0 350.0 true true PENS "unattached" 1.0 0 -65413 true "heads" 1.0 0 -256 true "bodies" 1.0 0 -16745473 true "tails" 1.0 0 -16711936 true SWITCH 90 263 180 296 plot? plot? 0 1 -1000 @#$#@#$#@ WHAT IS IT? ----------- In Follower, turtles attempt to "connect" with other turtles, forming long chains according to a small set of simple rules. In the model, a turtle can follow only ONE other turtle, and similarly it can only be followed by ONE other turtle. This means there are four turtle states, each represented by a different color: Pink: Unattached Green: Following another turtle (a "tail") Yellow: Being followed by another turtle (a "head") Blue: Following and being followed by other turtles (a "body" segment) Turtles are created in the pink (unattached) state. At each turn, each turtle checks a random patch in a square donut shape around itself. If it finds a turtle there who is not already being followed, it will "latch on" and start following the movements of that turtle. An unattached turtle (one that has not yet "latched on" to another turtle) will move randomly. HOW TO USE IT -------------- SETUP: Clears the graphics window and creates the number of turtles specified in the NUMTURTLES slider. All the turtles are created in an unattached state (pink). GO: Runs the simulation. NUMTURTLES: Specifies the number of turtles created in SETUP. NEAR-RADIUS: The inner radius of the square donut turtles search in. FAR-RADIUS: The outer radius of the square donut turtles search in. WAVER: The amount of randomness in the movement of non-following turtles. There is also a plot called "Turtle Count" that displays, over time, the number of turtles in each state. You can turn the plot on and off with the PLOT? switch. THINGS TO NOTICE ---------------- Each of the sliders has a different effect on the simulation. Notice that the when the number of turtles is high, chains tend to form very quickly. This is because there are more turtles and therefore more chances for each turtle to attach on each turn. Varying the size of the donut tends to affect how the turtles start to attach, but in the long run doesn't have a big effect on the simulation outcome. Donut size is most interesting at very small values, which causes the turtles to attach into very small loops. Also, very large thick donuts (big FAR-RADIUS, small NEAR-RADIUS) looks interesting with a large number of turtles. The amount of movement randomness (set by WAVER) can also change the simulation outcome. Very high values for WAVER result in small loops being formed because the turtles are continuously moving over themselves, increasing the chances of connecting the head of the chain to its tail. The simulation, under any parameters, moves towards forming loops. Loops may be formed by wrapping around the screen, but in almost all cases if the simulation is left running long enough you will get many small loops or one big loop. It is possible that a chain will never connect to itself if the WAVER slider is set to zero, but otherwise the simulation should proceed towards loops. THINGS TO TRY ------------- Try making the waver setting very high. Notice how the turtles clump up into little clusters. This is because they are moving over themselves frequently, which increases the chances of attaching to their tail. This makes sense if the donut allows the turtles to check close to themselves, but if it does not (NEAR-RADIUS is big) then the same thing still happens. Why is this the case? Notice that we are plotting all four possible turtle states, but only three appear on the plot. Do you know why? EXTENDING THE MODEL ------------------- Try implementing different rules for how turtles follow each other. For instance, interesting results can be seen if the "towards-nowrap" primitive is used. You might also try giving the turtles a certain probability of breaking apart again. See how this affects the patterns they make. NETLOGO FEATURES ---------------- Note the use of the "towards" primitive to make the turtles follow each other. Note also that we must be very careful to ensure that we never have two turtles following the same leader. CREDITS AND REFERENCES ---------------------- To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Follower model. http://ccl.northwestern.edu/netlogo/models/Follower. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL. In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Follower for terms of use. @#$#@#$#@ default true 0 Polygon -7566196 true true 150 5 40 250 150 205 260 250 body true 0 Line -7566196 true 148 297 148 0 @#$#@#$#@ NetLogo 2.0beta1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@