This page was automatically generated by NetLogo 4.1. Questions, problems? Contact feedback@ccl.northwestern.edu.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Sun's Java site.


In order for this to work, this file, your model file (Moths.txt), and the file NetLogoLite.jar must all be in the same directory. (You can copy NetLogoLite.jar from the directory where you installed NetLogo.)

On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.

You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.

If NetLogoLite.jar and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of NetLogoLite.jar in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)

powered by NetLogo

view/download model file: Moths.txt

WHAT IS IT?

This section could give a general understanding of what the model is trying to show or explain.


HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.


HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.


THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.


THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.


EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.


NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.


RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.


CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.


PROCEDURES

breed [moth]
moth-own [genes]
breed [bird]

globals [freqD freqL year clock clock-start Lbef Dbef caught caughtL caughtD TotTime lichen]

to startup
  reset
end

to reset
  clear-all
  set-default-shape bird "nuthatch"
  set freqD .03
  set lichen 38
  setup-patches
  setup-moths
  setup-bird
  set year 1830
end

to setup-patches
  if year < 1835 [import-pcolors "mothbackdrop1.jpg"]
  if year >= 1835 and year <= 1950 [import-pcolors "mothbackdrop2.jpg"]
  if year > 1950 [import-pcolors "mothbackdrop3.jpg"]
  if year >= 1835 and year < 1900 and lichen > 0 [set lichen lichen - 3]
  if year > 1954 and lichen < 38 [set lichen lichen + 3]
  ask patches
  [
    if pcolor = black and random 100 < 40 [set pcolor 1.3]
    if pcolor <= 1.3  and random 100 < lichen [set pcolor white]
  ]
end

to setup-moths
if freqD < 0.05 [set freqD .05 + (random 5 / 1000)]
if freqD > .75 [set freqD .7 + (random 10 / 1000)]
create-moth 20
[
  if random 1000 / 1000 < freqD [set genes 1] 
  if random 1000 / 1000 < freqD [set genes genes + 1]
  ifelse  genes < 1 [set shape "mothL"][set shape "mothd"]
  set ycor 5 + random 263
  let x random 3
    if x = 0 [set xcor 127 + random 36]
    if x = 1 [set xcor 210 + random 43]
    if x = 2 [set xcor 285 + random 38]
  set size 13
]
end

to setup-bird
  create-bird 1 [
    set size 55
    hide-turtle
  ]
end

to go
if clock-start = 0 
[
  set freqD (count moth with [genes = 1] + (2 * count moth with [genes = 2]))/ (count moth * 2)
  ask moth [die]
  setup-patches
  setup-moths
  set caughtL 0 set caughtd 0 set TotTime TotTime + forage-time
  set Lbef count moth with [genes < 1]
  set Dbef count moth with [genes >= 1] 
  set clock-start timer 
]
set clock timer - clock-start
eat-moths

if clock > forage-time 
[ 
  set year year + 2 
  set clock-start 0 
  ask bird [hide-turtle] 
  set caughtL Lbef - count moth with [genes < 1]
  set caughtD Dbef - count moth with [genes >= 1]
  do-plots
  set clock 0 
  stop
]
end

to eat-moths
  ;; show the hawk shape under the mouse-pointer
  ask bird [
    set hidden? not mouse-inside?
    if mouse-down? = false [setxy mouse-xcor mouse-ycor]
  ]
  if mouse-inside? and mouse-down? [
    ;; prey holds an agentset of the bugs that the mouse is close to touching.
    ;; "close to touching" is considered to be within a circle that is equal in size to the size
    ;; of the bug.  The shape of the bug may not take up the whole circle, but it takes up most of it.
    let prey moth with [distance one-of bird < (size / 2)]
    if any? prey [
      set caught (caught + count prey)
      ask prey [ die ]
    ]
  ]
end

to do-plots
set-current-plot "Dark Allele Frequency"
set-current-plot-pen "FreqD"
plotxy year freqD

set-current-plot "relative Survival"
if lbef > 0
[
  set-current-plot-pen "Light"
  plotxy year ((lbef - caughtl) / (Lbef))
]
if dbef > 0
[
  set-current-plot-pen "Dark"
  plotxy year ((Dbef - caughtD) / (Dbef))
]
end

to skip
if year < 1950
[
  set year 1950
  set freqD .75
  set lichen 0
]
end