caterpiller

No preview image

1 collaborator

Default-person Revital Peleg (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.0.3 • Viewed 136 times • Downloaded 7 times • Run 0 times
Download the 'caterpiller' modelDownload this modelEmbed this model

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


WHAT IS IT?

HOW IT WORKS

HOW TO USE IT

Notes:

THINGS TO NOTICE

THINGS TO TRY

EXTENDING THE MODEL

NETLOGO FEATURES

RELATED MODELS

CREDITS AND REFERENCES

Comments and Questions

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

Click to Run Model

;; caterpillars  are  breeds of turtle.
breed [ caterpillars caterpillar ]  ;; 
turtles-own [energy]       ;; caterpillars have energy
patches-own [countdown]

to setup
  clear-all
  ask patches [ set pcolor green ]
  ;; check GRASS? switch.
  ;; if it is true, then grass grows and the caterpillars eat it
  ;; if it false, then the caterpillars don't need to eat
  if grass? [
    ask patches [
      set countdown random grass-regrowth-time ;; initialize grass grow clocks randomly
      set pcolor one-of [green brown]
    ]
  ]
  set-default-shape caterpillars "caterpillar"
  create-caterpillars initial-number-caterpillar  ;; create the caterpillarss, then initialize their variables
  [
        set size 4  ;; easier to see
    set label-color white
    set energy random (10 * caterpillar-gain-from-food)
    setxy random-xcor random-ycor
  ]
    display-labels
  update-plot
end 

to go
  if not any? turtles [ stop ]
  ask caterpillars [
    move
    if grass? [
      set energy energy - 2  ;; deduct energy for caterpillars only if grass? switch is on
      eat-grass
    ]
    reproduce-caterpillars
    death
  ]
    if grass? [ ask patches [ grow-grass ] ]
  tick
  update-plot
  display-labels
end 

to move  ;; turtle procedure
  rt random 50
  lt random 50
  fd 2
end 

to eat-grass  ;; caterpillars procedure
  ;; caterpillars eat grass, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + caterpillar-gain-from-food  ;; caterpillars gain energy by eating
  ]
end 

to reproduce-caterpillars  ;; caterpillars procedure
  if random-float 100 < caterpillar-reproduce [  ;; throw "dice" to see if you will reproduce
    set energy (energy / 10)                ;; divide energy between parent and offspring
    hatch 1 [ rt random-float 360 fd 1 ]   ;; hatch an offspring and move it forward 1 step
  ]
end 

to death  ;; turtle procedure
  ;; when energy dips below zero, die
  if energy < 0 [ die ]
end 

to grow-grass  ;; patch procedure
  ;; countdown on brown patches: if reach 0, grow some grass
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown grass-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end 

to update-plot
  set-current-plot "populations"
  set-current-plot-pen "caterpillars"
  plot count caterpillars
  if grass? [
    set-current-plot-pen "grass"
    plot count patches with [pcolor = green]  ;; divide by four to keep it within similar
    ]
end 

to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
     if grass? [ ask caterpillars [ set label round energy ] ]
  ]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Revital Peleg almost 9 years ago (Default description) Download this version
Revital Peleg almost 9 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.