Created
February 2, 2017 03:21
-
-
Save kf0jvt/b8877d9acf67cdce95006a31c5901468 to your computer and use it in GitHub Desktop.
netlogo termites picking up any color
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; create a variable for termites to know | |
; what color chip they carry | |
turtles-own [chip_color] | |
to setup | |
clear-all | |
set-default-shape turtles "bug" | |
;; randomly distribute wood chips | |
ask patches | |
; a set of patches will change their color | |
; based on the density selected by the user. | |
; of those, half will change their color to | |
; yellow and the other half to green | |
[ if random-float 100 < density | |
[ set pcolor yellow | |
if random 2 < 1 [ | |
set pcolor green] ] ] | |
;; randomly distribute termites | |
create-turtles number [ | |
set color white | |
setxy random-xcor random-ycor | |
set size 5 ;; easier to see | |
] | |
end | |
to go ;; turtle procedure | |
search-for-chip | |
find-new-pile | |
put-down-chip | |
end | |
to search-for-chip ;; turtle procedure -- "picks up chip" by turning orange | |
; originally this looked for the patch color to be yellow. Now we are extending it | |
; to match yellow or green. | |
ifelse pcolor = yellow or pcolor = green | |
[ set chip_color pcolor | |
set pcolor black | |
set color orange | |
fd 20 ] | |
[ wiggle | |
search-for-chip ] | |
end | |
to find-new-pile ;; turtle procedure -- look other chips | |
; It has to find a yellow or green patch and that patch must also | |
; match the color of the chip it is holding | |
if chip_color = yellow and pcolor != yellow | |
[ wiggle | |
find-new-pile ] | |
if chip_color = green and pcolor != green | |
[ wiggle | |
find-new-pile ] | |
end | |
to put-down-chip ;; turtle procedure -- finds empty spot & drops chip | |
ifelse pcolor = black | |
[ set pcolor chip_color | |
set color white | |
get-away ] | |
[ rt random 360 | |
fd 1 | |
put-down-chip ] | |
end | |
to get-away ;; turtle procedure -- escape from yellow piles | |
rt random 360 | |
fd 20 | |
if pcolor != black | |
[ get-away ] | |
end | |
to wiggle ; turtle procedure | |
fd 1 | |
rt random 50 | |
lt random 50 | |
end | |
; Copyright 1997 Uri Wilensky. | |
; See Info tab for full copyright and license. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment