Garden ecosystem

No preview image

1 collaborator

Default-person Becca Shareff (Author)

Tags

biology 

Tagged by Becca Shareff almost 7 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3.1 • Viewed 404 times • Downloaded 32 times • Run 0 times
Download the 'Garden ecosystem' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [farmers farmer]
breed [plants plant]
breed [weeds weed]


turtles-own [energy my-heading]
patches-own [nutrients fertile] ;; nutrients determines the soil quality. fertile determines if a seed can be sprouted there; affected by spacing.

globals [
  total-harvested;; lbs of produce harvested by the farmer
  money;; budget for the project
crop
]

to setup
  clear-all
  setup-patches
  setup-turtles
  make-farmer
  reset-ticks
  set money (budget - (count plants * plant-cost))
end 

to setup-patches
  ask patches [
   set nutrients (random 15) ]
  repeat 5 [diffuse nutrients 1]
  ask patches [
   set pcolor scale-color brown nutrients  10 0
   if remainder pxcor spacing = 0 and remainder pycor spacing = 0 [set fertile true ]]
end 

to setup-turtles
  create-weeds 0
end 

to make-farmer
  create-farmers 1 [
    set color cyan
    set size 3
    set shape "farmer"
    setxy 0 0
    set heading 90
    set my-heading 270
    run "seed"
  ]
end 

to seed
  repeat (number-plants)
[
 ask farmers [
  (ask patch-here [
      if fertile = true and not any? plants-here [
        sprout-plants 1 [
          set shape "plant"
          set size 0.2
          set energy 2
        ]]])
  fd (spacing)
  if not can-move? 1 [
    set heading 0
    fd spacing
    set heading my-heading
    ifelse my-heading = 90 [set my-heading 270] [set my-heading 90]

  ]]

]
end 

to re-seed
  repeat (number-plants * spacing)
[
  ask farmers [fd spacing
  (ask patch-here [
      if fertile = true and not any? plants-here [
        sprout-plants 1 [
          set shape "plant"
          set size 0.2
          set energy 2
        ]]])
  if not can-move? 1 [
    set heading 0
    fd spacing
    set heading my-heading
    ifelse my-heading = 90 [set my-heading 270] [set my-heading 90]

  ]]]
end 

to go
      animate
       tick
end 

to animate
 ask turtles [
   run word breed "-grow"
   run word breed "-check-if-dead"
   run word breed "-eat" ]
  ;wait 1
 if any? patches with [not any? plants-here and nutrients > 5] [
   ask one-of patches with [not any? plants-here and nutrients > 5] [
    sprout-weeds 1 [
      set breed weeds
      set shape "flower budding"
      set color lime
      set energy 1
      set size 0.03;; somehow I want to adjust this so that plants are more likely to appear in spaces with high nutrient level
harvest-plants
 harvest-weeds
    ]]]
end 

to plants-grow
  if (energy > 3) [set size size + 0.02]
end 

to weeds-grow;;
    if (energy > 2) [set size size + 0.04];; arbitrary numbers but weeds grow faster
end 

to farmers-grow
end 

to plants-check-if-dead
  if (energy <= 0) [
    set nutrients (nutrients + 0.5)
    set pcolor scale-color brown nutrients 10 0
    die
    ]
  ;;maybe have them "flash" before they die, or 'turn red, wait 3' so we know to look at them **note that i can't get this part to work. they freeze up.
end 

to weeds-check-if-dead
  if (energy <= 0) [ die ]
end 

to farmers-check-if-dead
end 

to plants-eat
  if (nutrients >= 1) [
      set energy energy + 1
      set nutrients (nutrients - 0.2)
      ask neighbors4 [set nutrients (nutrients - 0.05)
        set pcolor scale-color brown nutrients 10 0];; plants slowly take nutrients from soil
      set pcolor scale-color brown nutrients 10 0]
  if (nutrients < 1) [
      set energy energy - 0.1];; if no nutrients in the soil, this arbitrary rate is how fast they will die
end 

to weeds-eat
  if (nutrients >= 1) [
  set energy energy + 1
  set nutrients (nutrients - 0.1)
  ask neighbors4 [
    set nutrients (nutrients - 0.08)
    set pcolor scale-color brown nutrients 10 0];; weeds take nutrients from soil less quickly
  set pcolor scale-color brown nutrients 10 0]
  if (nutrients < 1) [
  set energy energy - 0.1];; if no nutrients in the soil, this arbitrary rate is how fast they will die
end 

to farmers-eat
end 

to harvest-plants
  ask farmers [
    set hidden? not mouse-inside?
    setxy mouse-xcor mouse-ycor
  ]
  if mouse-inside? and mouse-down? [
    set crop plants with [distance one-of farmers < (size / 2)]
    if any? crop [
      let weight sum [size] of crop
      set total-harvested (total-harvested + (ceiling (1.5 * weight * count crop)))



ask crop [ die ]
    ]]
end 

to harvest-weeds
  ask farmers [
    set hidden? not mouse-inside?
    setxy mouse-xcor mouse-ycor
  ]
  if mouse-inside? and mouse-down? [
    let weedable weeds with [distance one-of farmers < (size * 2)]
    if any? weedable [

ask weedable [ die ]
    ]
  ]
end 

to add-compost
  ask patches [set nutrients (nutrients + 5) set pcolor scale-color brown nutrients 10 0 ]
set money (money - 20)
end 

to add-herbicide
  ask weeds [die]
  ask plants [
    set energy energy - 2]
  ask patches [set nutrients (nutrients - 2) set pcolor scale-color brown nutrients 10 0 ]
set money (money - 30)
end 

There is only one version of this model, created almost 7 years ago by Becca Shareff.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.