food-seeker_2009


Information

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


WHAT IS IT?


An agent seeks "food"--A demonstration of the use of in-cone for turtle vision, and how difference settings for in-cone affect the speed of a model.

HOW TO USE IT


Click GO. Click RESET to reset the model.
Adjust the sliders and switches to see the effect of those changes on the model performance.

THINGS TO NOTICE


Notice how NO-WRAP increases the speed of the model. The underlying processes for NO-WRAP are less than needed without it.
However, note that with world-wrapping turned off in the view settings, both the regular and no-wrap version are about the same speed, and faster then no-wrap with world-wrapping turned on.
Notice how the larger the area (longer vision, wider angle), the more things slow down.

NETLOGO FEATURES


This model uses a turtle shape that has parts that extend beyond the normal boundaries of the shape-editor box.
This model also achieves some performance gains by minimizing the number of patches addresed in ASK clauses. This is especially important to speed up the drawing and erasing of the vision shadow.

RELATED MODELS


See also the "Vision Cone Example" in the NetLogo models Library.

INFO


Summary | In-cone turtle-vision demonstration |

Copyright | 2004,2009 James P Steiner |

Procedures

NetLogo Version: NetLogo 4.0.4

globals 
[ 
  food-color
  shadow-color
  ground-color
  eaten-color
  greeting?
]

patches-own
[ freshness ;; matched with ticker to indicate freshness of change
]

turtles-own
[ prior-not-food
]

to go
   ask turtles
   [
     ;; remove greeting text, if present
     if greeting? != false [ greeting false ]
     
     
     ;; if the turtle is standing on food, eat it
     if shade-of? food-color pcolor
     [ set pcolor eaten-color 
       set label label + 1
     ]
     
     ;; initialize visi-cone
     let visi-cone 0
     
     ;; get patches in vision--two versions, one with no-wrap, one without no-wrap
     ifelse no-wrap?
     [ set visi-cone patches in-cone-nowrap (world-width * vision-range) vision-width ]
     [ set visi-cone patches in-cone        (world-width * vision-range) vision-width ]
     
     ;; food are visible patches that are the food color
     let food visi-cone with [ shade-of? food-color pcolor ]
     
     ;; not-food are visible patches that are the ground color
     let not-food visi-cone with [ shade-of? ground-color pcolor ]
  
     ;; (neither of the above contains any eaten patches)
     
     ;; change color to show range of in-cone  
     ;; mark for later erasing of the shadow
     ask not-food 
     [ set pcolor shadow-color
       set freshness ticks 
     ]
  
     ;; previously visible patches with a stale marker are changed back
     ask prior-not-food with [ freshness != ticks ] [ set pcolor ground-color ]
  
     ;; (this is to improve speed of shadow drawing, vs. resetting color
     ;; of ALL patches, or even of all prviously shadowed patches
     
     if not is-patch? patch-ahead 1 [ rt 175 + random-float 10  ]
     
     ifelse any? food
     [ set color orange ;; indicates food in sight
       jump speed      ;; move forward, maybe towards the food
     ]
     [ set color violet ;; indicates no food visible
       rt 15 - random 30 ;; change heading.. hope to find some food
       jump .1 * speed   ;; move forward, slowly
     ]
     
     ;; store the set of visible not-food (for erasing on next pass
     set prior-not-food not-food
     
     ;; some food grows back
     if random 300 = 1
     [ let eaten patches with [ pcolor = eaten-color ]
       if any? eaten
       [ ask one-of eaten [ set pcolor food-color ]
       ]
     ]
  ]
     ;; increment freshness ticker
     tick
end

to setup
   ca
   set food-color lime
   set eaten-color yellow - 3 ;; can be ANY color besides food or ground shades
   set ground-color black  
   set shadow-color gray  ;; MUST be shade of ground-color

   crt 1
   [ set size 5
     set color white
     set label 0
     set shape "seeker"
     set prior-not-food (patches with [ false ])
   ]
   ask patches
   [ if random 100 < 5 [ set pcolor food-color ]
   ]
   greeting true
end

to startup
   setup
end
   
   
to greeting [ show? ]
   ifelse show?
   [ set greeting? true
     ask patch max-pxcor (max-pycor - 1)
     [ set plabel "Click GO to begin animation" ]
   ]
   [ set greeting? false
     ask patch max-pxcor (max-pycor - 1)
     [ set plabel "" ]
   ]
end      

                    


Download Link

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