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 @#$#@#$#@ GRAPHICS-WINDOW 186 10 553 398 25 25 7.0 1 24 1 1 1 0 1 1 1 -25 25 -25 25 1 1 1 ticks CC-WINDOW 5 412 562 507 Command Center 0 BUTTON 114 10 177 43 reset setup NIL 1 T OBSERVER NIL NIL NIL NIL BUTTON 11 10 74 43 GO go T 1 T OBSERVER NIL NIL NIL NIL SLIDER 6 94 179 127 vision-range vision-range 0.1 1.0 0.45 0.05 1 NIL HORIZONTAL SLIDER 6 130 178 163 vision-width vision-width 5 180 70 5 1 degrees HORIZONTAL SLIDER 6 166 178 199 speed speed 0.1 1 0.2 0.1 1 patches HORIZONTAL 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. 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 | @#$#@#$#@ 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 4.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 0.0 1.0 0.0 1 1.0 0.0 0.2 0 0.0 1.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@