Created
November 30, 2022 18:59
-
-
Save shawngraham/76412d2b636687a07639ce22ecc6ab86 to your computer and use it in GitHub Desktop.
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
extensions [import-a fetch] | |
;;; SETUP PROCEDURE | |
to setup | |
clear-all | |
let thing (fetch:url (word "https://raw.githubusercontent.com/SantaFeInstitute/ABMA/master/ch1/ch1_map.png")) | |
import-a:pcolors thing | |
create-turtles 20 ; create 20 agents | |
[ ; with the following state variables: | |
set color random 140 ; color | |
set size 2 ; size | |
set shape "turtle" ; shape | |
; setxy random 5 random 5 ; location | |
setxy ( 360 + random 5 ) ( 170 + random 5 ) | |
] | |
reset-ticks | |
end | |
to go | |
; at each time step turtles reproduce with a probability equal to the pop_growth (slider) | |
ask turtles [ | |
;rt random 360 ; this is previous code used to move turtles around | |
;fd 1 | |
if random-float 1 <= pop_growth ; this version is driven by population growth (slider) | |
[ reproduce ] ; the reproduction procedure is defined below | |
] | |
tick | |
end | |
to reproduce | |
; turtles reproduce only if there is an unoccupied patch in their surrounding that is not water | |
if any? neighbors4 with [count turtles-here = 0 AND pcolor != white] [ | |
let empty-patch one-of neighbors4 with [count turtles-here = 0 AND pcolor != white] | |
hatch 1 [ | |
set color color + 0.1 ; new turtles are clones of parents but we change the color a bit | |
move-to empty-patch ; move the newly hatched turtle to a new patch | |
] | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment