turtles-move-on-gradient


Information

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


WHAT IS IT?


-------
This section could give a general understanding of what the model is trying to show or explain.

HOW IT WORKS


--------
This section could explain what rules the agents use to create the overall behavior of the model.

HOW TO USE IT


---------
This section could explain how to use the model, including a description of each of the items in the interface tab.

THINGS TO NOTICE


------------
This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY


---------
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL


---------------
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES


------------
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS


----------
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

CREDITS AND REFERENCES


------------------
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.

Procedures

NetLogo Version: NetLogo 4.0.4

globals
[ queue 
  old-grad
]

turtles-own
[ age
  value
]
patches-own
[ grad
]



to setup
   ca
   draw-gradient
   set-default-shape turtles "circle"
   ask patches
   [
     if random-float 100 < density
     [ sprout 1
       [ set value random-float 100
         set color scale-color blue value -5 105
       ]
     ]
   ]
   set queue []
end

to go
   set queue sort-by [ [ value ] of ?1 < [ value ] of ?2 ] turtles
   foreach queue
   [ ask ?
     [ let my-value value
       let inferiors
           (patches in-radius 3) with
           [     grad <= [ grad ] of myself 
             and (    not any? turtles-here 
                   or any? turtles-here with
                      [ value < my-value ] 
                 )
             ]
     if any? inferiors
     [ let inferior min-one-of inferiors [ grad - ifelse-value any? turtles-here [ [ value ] of one-of turtles-here ] [ 0 ]]
       let here patch-here
       ask [ turtles-here ] of inferior
       [ move-to here ]
       move-to inferior
      ]
   ]
   ]
   set queue but-first queue
   every .1
   [ if stir? 
     [ if-else gradient + 1 > 180 [ set gradient -180 ] [ set gradient gradient + 1 ]
     ]
   ]
   tick
end

to draw-gradient
   let grad-x sin gradient
   let grad-y cos gradient
   let grad-min min (list min-pxcor min-pycor)
   let grad-max max (list max-pxcor max-pycor)
   ask patches
   [ set grad (scale-color
                   gray
                   ((grad-y * pycor) + (grad-x * pxcor))
                   grad-min
                   grad-max
                 )
                 
     if-else abs (grad - 5) < .2 [ set pcolor black ] [ set pcolor grad ]                   
   ]
end
   
   
to-report monitor-grad
   if gradient != old-grad
   [ set old-grad gradient
     draw-gradient 
     display
   ]
   report "OK"
end
   
   
   
   
   

                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download turtles-move-on-gradient --