powered by NetLogo

view/download model file: Slime_Mold_Demo.nlogo

 

PROCEDURES

;;; Initialization
 
turtles-own [
    rest-time
    ]
patches-own [
    chemical
    border?
    food?
    ]
 
;;; Setup Procedures
to setup
  ca
;  cct number [
 ;           set color red 
 ;           setxy random-float screen-size-x random-float screen-size-y
;            set rest-time 0]
  ask patches [set chemical random-float 0
               set border? false
               set food? false 
               make-border
               if not border? [if random-float 1 < density [sprout 1 [ set color red set rest-time random-float 0]]]]
end
      
 
 
;; Main Program
 
to go
ask turtles [ ifelse hide? [set hidden? true]
                           [set hidden? false]
              ifelse rest-time = 0 
                    [ if chemical > chem-threshold
                          [ set chemical chemical + chem-release 
                            set rest-time refactory] 
                     if chemical > 0.01 [
                               let p max-one-of neighbors [chemical]
                               if [chemical] of p > chemical [face p
                             ;  fd speed ] ]
                             ; if not any? (turtles-on patch-ahead 1)[ fd speed]
                               ]] ;fd speed
                   ifelse [pcolor] of patch-ahead 1 = blue [set heading random 360  ] [  fd speed ]
                     set color red]
                    [ set rest-time rest-time - 1 
                      set color yellow ]
        ;    wiggle 
            ]
diffuse chemical diffusion-rate
;ask patch 0 0 [set chemical chemical + food-release]
ask patches [   
            ifelse border? 
              [ set chemical 0]
              [ set chemical chemical * (1 - evaporation-rate)
                set pcolor scale-color green  chemical 0 100 ] 
            if food? [set chemical chemical + food-release]    ]
ifelse placing-food? [draw-food][draw-border]
end
 
 
;; Procedures
 
to draw-food
  if mouse-down? [ask patch mouse-xcor mouse-ycor [set pcolor white
                                                       set food? true]]
end
 
 
to wiggle
  rt random wiggle-angle
  lt random wiggle-angle
  fd speed / 10
end
 
to make-border  ;; patch procedure
    if (distancexy-nowrap 0 0 )> max-pxcor [set pcolor blue
                                                set border? true
                                                ask turtles-here [die]]
end
 
to draw-border
  if mouse-down? [ask patch mouse-xcor mouse-ycor [set pcolor blue
                                                       set border? true
                                                       ask turtles-here [die]]]
end