Bug Hunt Camouflage

Bug Hunt Camouflage preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Default-person Michael Novak (Author)

Tags

biology 

Tagged by Reuven M. Lerner almost 11 years ago

evolution 

Tagged by Reuven M. Lerner almost 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 1108 times • Downloaded 119 times • Run 2 times
Download the 'Bug Hunt Camouflage' 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?

This is a model of natural/artificial selection that shows how a population hunted by a predator can develop camouflaging. For example, in a forest with green leaves, green bugs may emerge as the predominant bug color.

When a predator uses color and shape to identify the location of prey in an environment, then the colors and patterns in the environment provide additional selective pressure on the prey. If some prey tend to blend into the background better, they tend to survive longer and reproduce more often. If this continues over many generations, the distribution of colors in a population may shift to become better camouflaged in the surrounding environment.

HOW IT WORKS

You assume the role of a predator bird. After you press GO, click on bugs as fast as you can using your mouse. You may also keep the mouse button depressed, and move the cursor around the world.

You can watch your consumption by watching the "Bugs Caught vs. Time" plot. As its slope decreases, you efficiency (or, in other words, your rate of bug consumption) is decreasing. Also, the time to catch a batch of bugs is plotted in the "Time to Catch 10 Bugs" plot.

Try to consume bugs as fast as possible to remove any "deliberation" on your part as a predator. The camouflaging effect will emerge more clearly if you aren't taking your time trying to find bugs that typically would be more difficult to find.

Bugs have 3 genes that determine their phenotype for color. One gene is RED-PIGMENT-GENE-FREQUENCY, another is GREEN-PIGMENT-GENE-FREQUENCY, and the last is BLUE-PIGMENT-GENE-FREQUENCY. The more frequently the gene for a pigment is coded for, the stronger that presence of color is in the overall blend of pigments that results in a single phenotype for coloration (determined by an RGB [Red-Green-Blue] calculation).

With each bug you eat, a new bug is randomly chosen to reproduce one offspring. The offspring's gene-frequency for each of the three pigment genes may be different than the parent (as determined by the MUTATION-STEP slider).

HOW TO USE IT

CARRYING-CAPACITY determines the size of the population on SETUP, and how many bugs are in the world at one time when GO is pressed and bugs are being eaten.

MAX-MUTATION-STEP determines how much the pigment genes can drift from their current values in each new generation. For example, a MUTATION-STEP of 1 means that the gene frequency for any of the three pigments could go up 1, down 1, or not change at all in the offspring.

OFFSPRING-DISTANCE determines how far away (in patches) an offspring could show up from a parent. For example, a distance of 5 means the offspring could be 0, 1, 2, 3, 4, or 5 patches away from the parent.

BUG-SIZE can be changed at any time during GO or before SETUP to modify the size of the shapes for the bugs.

SHOW-GENOTYPE? reveals the RGB (Red-Green-Blue) gene frequency values for each bug. The values for Red can range from 0 to 100, and this also true for Green and Blue. These numbers represent how fully expressed each pigment is (e.g. 40-100-24 would represent genetic information that expresses the red pigment at 40% its maximum value, the green pigment at 100%, and the blue pigment at 24%.

ENVIRONMENT specifies the file name to load as a background image on SETUP or on CHANGE-ENVIRONMENT. The image file must be located in the same directory as the model.

MAKE-SINGLE-GENERATION creates one offspring from the existing bugs, without being limited by the CARRYING-CAPACITY. This can only be used, when the model is paused and GO is not running.

TOTAL-CAUGHT keeps track of how many bugs you have caught.

BUGS IN WORLD keeps track of how many bugs are in the world & view.

The plot "BUGS CAUGHT VS TIME" give a measure of your progress and performance as a predator.

The plot of "AVERAGE HSB VALUES" shows how the average values for the hue, saturation, and brightness of the bugs changes over time.

The histograms of "CURRENT HUES" and "INITIAL HUES" shows a distribution of hues in the current and starting populations.

The histograms of "CURRENT SATURATIONS" and "INITIAL SATURATIONS" shows a distribution of saturations (of colors) in the current and starting populations. Low values represent "grayish" colorations and high values represent "vivid" colorations.

The histograms of "CURRENT BRIGHTNESSES" and "INITIAL BRIGHTNESSES" shows a distribution of brightnesses (of colors) in the current and starting populations. Low values represent "dark" colorations and high values represent "light" colorations.

The plot of "VECTOR DIFFERENCE IN AVERAGE GENOTYPE" shows how the average values the genotype of the population change overtime. The plot shows the vector difference between the average value of red gene frequency, green gene frequency, and blue gene frequency for the current population as compared to the initial population.

THINGS TO NOTICE

The first thing that you will notice is that, over time, bugs will become harder and harder to detect in the environment. The completely random mutation process is pushed in a particular direction due to selective pressure which you unintentionally exert on the bugs.

Camouflaging emerges from the interaction of genes that encode for color, selective pressure, and small random changes (mutations) that accumulate in the offspring of survivors.

Each new offspring starts at zero size and grows to full size (specified by BUG-SIZE) after a while. This growth in size is included to make brand new offspring harder to detect. If newly created offspring were full sized right away, your eyes would more easily detect the "flash effect" created by sudden appearance of something new on a static background.

Sometimes two or more "near background" colors emerge as a predominant feature in a population of bugs. An example of this is the appearance of mostly green and red bugs in the poppy field, or dark blue/black and snow blue in the glacier background. Other times, the saturation of the bugs appears to be selected for. An example of this is a common outcome of "shell colored" bugs on the seashore background (e.g. light yellow, light tan, and light blue bugs similar to the shells of the seashore).

Larger numbers of bugs tend to take longer to start camouflaging.

In environments that have two distinct areas (such as a ground and sky), each with their own patterns and background colors, you might see two distinct populations of different camouflaging outcomes. Often, while hunting in one area, you will be surprised to look over at the other area (after they hadn't been paying attention to that area in a while) and notice that now there are a bunch of bugs in that background that blend in this new area very well, but whose colors are distinctly different than those that blend into the original area you were hunting in.

THINGS TO TRY

Try this model with a user who has never seen it. A common response from the user (within about 1 minute of interaction with the model) is "where did the bugs all go?" If you keep playing with the model, the user might get better at finding the bugs, but if s/he keeps trying to catch bugs quickly, even an experienced user will find that the creatures will become very hard to find in certain environments.

Once you reach a point where you are having trouble finding the bugs, it is useful to either press FLASH to show where they are (and how they are camouflaged), or press CLEAR-BACKGROUND to enable you to study their color distribution and location.

EXTENDING THE MODEL

What if you could eat a batch of bugs (e.g. 5 or 10) before they reproduced?

What if bugs reproduced sexually and recombined gene frequencies in their offspring?

What if bugs moved?

NETLOGO FEATURES

import-drawing is the primitive that loads the image into the drawing, which in this case is merely a backdrop instead of something agents actually draw in.

Because this model depends on interaction with the user, we measure the passage of time in seconds. We use timer to measure how much time passes each time through go, and we use tick-advance to advance the clock by that amount. (A simpler approach would have been to not use the tick counter at all and only use timer, but the problem with timer is that it keeps advancing even when go isn't pressed.)

In the code for flashing the bugs, we use ask-concurrent. We could have avoided it as follows, but the downside is that an extra turtle variable would have been required.

  turtles-own [old-color]

  ask bugs [ set old-color color ]
  repeat 3 [
    ask bugs [ set color black ]
    display
    wait 0.1
    ask turtles [ set color white ]
    display
    wait 0.1
  ]
  ask bugs [ set color old-color ]
  display

RELATED MODELS

Bug Hunt Speeds
Peppered Moths

CREDITS AND REFERENCES

Inspired by this: BugHunt! Macintosh freeware: http://bcrc.bio.umass.edu/BugHunt/

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Novak, M. and Wilensky, U. (2005). NetLogo Bug Hunt Camouflage model. http://ccl.northwestern.edu/netlogo/models/BugHuntCamouflage. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2005 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

Click to Run Model

;; two breeds of turtle: bugs and predators

breed [bugs bug]

bugs-own [
  red-gene    ;; gene for strength of expressing red pigment (0-100)
  blue-gene   ;; gene for strength of expressing blue pigment (0-100)
  green-gene  ;; gene for strength of expressing green pigment (0-100)
  birthday    ;; when this bug was born
]


breed [predators predator]

globals [
  total-caught                  ;; running total of the total number of bugs caught
  interval-start                ;; what the the tick value was at the start of the
                                ;; current interval
  bugs-in-a-batch               ;; how many bugs must be caught in a batch. when this is reached,
                                ;; the time to reach this (the interval) is recorded
  interval-length               ;; how long it took to catch the last number of bugs-in-a-batch
  caught-in-current-batch       ;; how many bugs have been caught so far in this current interval
  batches                       ;; how many batches have been caught (for plotting)
  adult-age                     ;; the age at which recently hatched bugs become full sized
  max-number-of-hue             ;; scaling value for initial histograms
  max-number-of-saturation      ;; scaling value for initial histograms
  max-number-of-brightness      ;; scaling value for initial histograms
  avg-red-gene                  ;; mean avg-red-gene
  avg-init-red-gene             ;; mean avg-red-gene  initial value
  avg-green-gene                  ;; mean avg-green-gene
  avg-init-green-gene             ;; mean avg-green-gene  initial value
  avg-blue-gene                  ;; mean avg-blue-gene
  avg-init-blue-gene             ;; mean avg-blue-gene  initial value
  vector-difference

]

to setup
  clear-all
  set bugs-in-a-batch 10        ;; ten bugs must be caught to make a batch
  set adult-age 2               ;; take 2 seconds to grow to full size
  set-default-shape bugs "moth"
  set-default-shape predators "hawk"
  change-environment
  make-initial-bugs
  make-predator

  calculate-initial-gene-metrics
  calculate-gene-metrics

  reset-ticks
end 

to go
  reset-timer
  grow-bugs
  eat-bugs
  reproduce-bugs
  ;; update the view 20 times a second
  every 0.05 [ display ]
  ;; keep the tick counter in sync with how many seconds have passed.
  ;; we don't only want to count the time that passes while the GO
  ;; button is actually down, so that's why we do RESET-TIMER above,
  ;; so we can measure how time has actually been spent in GO.
  tick-advance timer

  ;; plotting takes time, so only plot 10 times a second
  every 0.1 [ calculate-gene-metrics update-plots ]
end 

to calculate-initial-gene-metrics
   set avg-init-red-gene mean [red-gene] of bugs
   set avg-init-green-gene mean [green-gene] of bugs
   set avg-init-blue-gene mean [blue-gene] of bugs
end 

to calculate-gene-metrics
   set avg-red-gene mean [red-gene] of bugs
   set avg-green-gene mean [green-gene] of bugs
   set avg-blue-gene mean [blue-gene] of bugs
   let red-component-difference (avg-red-gene - avg-init-red-gene)
   let green-component-difference (avg-green-gene - avg-init-green-gene)
   let blue-component-difference (avg-blue-gene - avg-init-blue-gene)
   set vector-difference sqrt ((red-component-difference ^ 2) + (green-component-difference ^ 2) + (blue-component-difference ^ 2))
end 

;;;;;;;;;;;;;;;;;;;
;; Setup Procedures
;;;;;;;;;;;;;;;;;;;

to make-initial-bugs
  create-bugs carrying-capacity [
    set size bug-size
    set birthday (- adult-age)  ;; start at full size
    ;; assign gene frequencies from 0 to 100, where 0 represents 0% expression of the gene
    ;; and 100 represent 100% expression of the gene for that pigment
    set red-gene (random 101)
    set blue-gene (random 101)
    set green-gene (random 101)
    setxy random-xcor random-ycor
    assign-genotype-labels
    set-phenotype-color
  ]
end 

;; creates the turtle that will follow the mouse pointer around and
;; represent the predator that the user is controlling

to make-predator
  create-predators 1 [
    set color white
    set size 4
    hide-turtle
  ]
end 


;;;;;;;;;;;;;;;;;;;;;
;; Runtime Procedures
;;;;;;;;;;;;;;;;;;;;;

to grow-bugs
  ask bugs [
    ;; show genotypes
    assign-genotype-labels

    ;; grow the newly hatched offspring until they reach their ADULT-AGE,
    ;; at which point they should be the full BUG-SIZE
    let age ticks - birthday
    ifelse age < adult-age
      [ set size bug-size * age / adult-age ]
      [ set size bug-size ]
  ]
end 

to eat-bugs
  ;; show the hawk shape under the mouse-pointer
  ask predators [
    set hidden? not mouse-inside?
    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 bugs with [distance one-of predators < (size / 2)]
    if any? prey [
      set total-caught (total-caught + count prey)
      ;; increment the number of bugs caught in this interval
      set caught-in-current-batch (caught-in-current-batch + count prey)
      ask prey [ die ]
    ]
  ]
end 

to reproduce-bugs
;; if the number of bugs in under the carrying capacity, bugs can generate offspring
;; otherwise no new bugs are to replace ones that are eaten
  if not any? bugs [ make-initial-bugs ]
  if count bugs < carrying-capacity [
    ask one-of bugs [ make-one-offspring ]
  ]
end 





;; ask every bug to make one offspring (no carrying-capacity limitations are placed on this)

to make-generation
   ask bugs [ make-one-offspring ]
end 

to make-one-offspring ;; turtle procedure
   ;; three possible random mutations can occur, one in each frequency of gene expression
   ;; the max-mutation-step determines the maximum amount the gene frequency can drift up
   ;; or down in this offspring
   let red-mutation   random (max-mutation-step + 1) - random (max-mutation-step + 1)
   let green-mutation random (max-mutation-step + 1) - random (max-mutation-step + 1)
   let blue-mutation  random (max-mutation-step + 1) - random (max-mutation-step + 1)
   hatch 1 [
     set size 0
     set red-gene   limit-gene (red-gene   + red-mutation)
     set green-gene limit-gene (green-gene + green-mutation)
     set blue-gene  limit-gene (blue-gene  + blue-mutation)
     set-phenotype-color
     set birthday ticks
     wander
   ]
end 

to wander ;; turtle procedure, makes bugs wander around randomly
   rt random 360
   fd random-float (offspring-distance + 1)
end 


;; imposes a threshold limit on gene-frequency.
;; without this genes could drift into negative values or very large values
;; (any value above 100%)

to-report limit-gene [gene]
  if gene < 0   [ report 0   ]
  if gene > 100 [ report 100 ]
  report gene
end 

to change-environment
  ;; loads an image as a background from the current directory the model was launched from
   import-drawing environment
end 

;; a visualization technique to find bugs if you are convinced they are not there anymore
;; it allows flashing without actually changing and recalculating the color attribute of the bugs

to flash-bugs
  ;; we use ASK-CONCURRENT here instead of ASK because when
  ;; the bugs WAIT, we want them all to wait together, not each
  ;; wait one at a time.
  ask-concurrent bugs [
    let old-color color
    repeat 3 [
      set color black
      display
      wait 0.1
      set color white
      display
      wait 0.1
    ]
    set color old-color
  ]
  display
end 


;;;;;;;;;;;;;;;;;;;;;;
;; Visualization procedures
;;;;;;;;;;;;;;;;;;;;;;

to assign-genotype-labels  ;; turtle procedure
  ifelse show-genotype?
    ;; we display the genotype without decimal digits, to make
    ;; the data display of this information less cluttered
    [ set label (word round red-gene "-"
                      round green-gene "-"
                      round blue-gene) ]
    [ set label "" ]
end 


;;;;;;;;;;;;;;;;;;;;;;
;; Genotype to Phenotype Conversion Procedures
;;;;;;;;;;;;;;;;;;;;;;


;; convert the genetic representation of gene frequency
;; into a phenotype (i.e., a color, using an RGB list
;; instead of a standard NetLogo color)

to set-phenotype-color  ;; turtle procedure
  ;; RGB lists are expected to be in the 0-255 range,
  ;; so we must convert from the 0-100 range in the genotype
  set color (list ((red-gene   / 100) * 255)
                  ((green-gene / 100) * 255)
                  ((blue-gene  / 100) * 255))
end 


; Copyright 2005 Uri Wilensky.
; See Info tab for full copyright and license.

There are 15 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 11 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Bug Hunt Camouflage Download this version

Attached files

File Type Description Last updated
Bug Hunt Camouflage.png preview Preview for 'Bug Hunt Camouflage' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.