;;;; SUMMARY ;; An agent seeks food (use of in-cone) ;;;; COPYRIGHT ;; Copyright (C) 2006 James P Steiner ;; Some Rights Reserved. ;; Licensed under Creative Commons at-nc-sa license ;; Visit CreativeCommons.org for details globals [ ticker ;; used to track patch changes food-color shadow-color ground-color eaten-color greeting? ] patches-own [ tick ;; 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 ] ;; increment freshness ticker set ticker ticker + 1 ;; 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 (screen-size-x * vision-range) vision-width ] [ set visi-cone patches in-cone (screen-size-x * 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 tick ticker ] ;; previously visible patches with a stale marker are changed back ask prior-not-food with [ tick != ticker ] [ 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 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 random-one-of eaten [ set pcolor food-color ] ] ] ] 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 cct 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 screen-edge-x (screen-edge-y - 1) [ set plabel "Click GO to begin animation" ] ] [ set greeting? false ask patch screen-edge-x (screen-edge-y - 1) [ set plabel no-label ] ] end @#$#@#$#@ GRAPHICS-WINDOW 186 10 616 461 17 17 12.0 1 24 1 1 1 0 1 1 1 CC-WINDOW 5 475 625 570 Command Center 0 BUTTON 114 10 177 43 reset setup NIL 1 T OBSERVER T NIL BUTTON 11 10 74 43 GO go T 1 T OBSERVER NIL NIL SLIDER 6 94 179 127 vision-range vision-range 0.1 1.0 0.5 0.05 1 NIL SLIDER 6 130 178 163 vision-width vision-width 5 180 30 5 1 degrees SLIDER 6 166 178 199 speed speed 0.1 1 0.3 0.1 1 patches SWITCH 7 58 118 91 no-wrap? no-wrap? 0 1 -1000 @#$#@#$#@ = 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. 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. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 seeker true 0 Line -1 false 150 150 150 -150 Circle -7500403 true true 120 120 60 @#$#@#$#@ NetLogo 3.0.2 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@