Bug Hunters Camouflage

Bug Hunters Camouflage preview image

2 collaborators

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

Tags

evolution 

Tagged by Reuven M. Lerner over 11 years ago

hubnet 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4-RC2 • Viewed 695 times • Downloaded 105 times • Run 2 times
Download the 'Bug Hunters 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 HubNet activity 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

Each HubNet participant or player assumes the role of a predator. When the HubNet simulation is started after pressing GO, participants should try to click on bugs as fast as they can with the mouse.

Each participant can monitor his or her relative success compared to other participants by watching the monitors in the client that show the TOP HUNTER (the person with most catches), how many that person caught (TOP HUNTER'S CATCHES) and the RELATIVE % they have caught compared to the best hunter (e.g. if the player has caught 40 and the best hunter has caught 80, then s/he has 50%).

Over time a small population of bugs will become harder and harder to detect in the environment (the environment is an image file that is loaded into the model). Camouflaging emerges from: 1) a selective pressure that results from the interaction of predator, prey, and environment, 2) the genetic representation for genes to show color, 3) and small random changes that accumulate in new offspring in the remaining population that tend to be more advantageous.

Trying to become the best hunter (in number of moth catches) in the HubNet environment helps simulate the competitive pressure for limited food resources that exists between individual predators in a population. Without this simulated competition, a participant could leisurely hunt for bugs regardless of how easy they are to catch or find. This would not put any selective pressure on the moth population over time, and so camouflaging would not emerge in the population.

Bugs have 3 genes that determine their phenotype for color. One gene is RED-GENE, another is GREEN-GENE, and the last is BLUE-GENE. 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, an existing bug is randomly chosen to reproduce one offspring. The offspring's gene-frequency for each of the three pigment genes may be slightly different than the parent (as determined by the MUTATION-STEP slider).

HOW TO USE IT

To run the activity press the GO button. To start the activity over with the same group of students stop the GO button by pressing it again, press the SETUP button, and press GO again. To run the activity with a new group of students press the RESET button in the Control Center.

Make sure you select Mirror 2D view on clients in the HubNet Control Center after you press SETUP.

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 MAX-MUTATION-STEP of 1 means that the gene frequency for any of the three pigments could go up 1, down 1, or stay the same 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 up to 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 255, and this also true for Green and Blue. These numbers represent how fully expressed each pigment is (e.g. 102-255-51 would represent genetic information that expresses the red pigment at 40% its maximum value, the green pigment at 100%, and the blue pigment at 20%.

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.

The plots "BUGS CAUGHT BY ALL HUNTERS VS. TIME" keeps track of how many bugs all the participants have caught.

There are several monitors TOP HUNTER reports the person with most catches and TOP HUNTER'S CATCHES reports how many they caught.

THINGS TO TRY

Larger numbers of bugs tend to take longer to start camouflaging, but larger numbers of prey (participants) speed up the emergence camouflaging in larger populations.

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.

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 sudden appearance of something new.

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.

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 bugs reproduced sexually and recombined gene frequencies in their offspring?

What if the shape of the bugs changed?

What if a second population of insects, with slightly different body shape, was poisonous, and lost points for the user when they selected it? Would the bugs drift to become more like this color (Mimicry), stay more like the environment, or some other outcome?

NETLOGO FEATURES

IMPORT-DRAWING is the primitive that loads the image into the drawing, which in this case is merely a backdrop.

IN-RADIUS is the primitive used to check if the mouse is within the graphical "footprint" of a turtle.

This model uses RGB colors, that is, colors expressed as a three item list of red, green and blue. This gives a large range of colors than with NetLogo colors.

RELATED MODELS

Bug Hunt Speeds Bug Hunt Camouflage Peppered Moths Guppy Spots

CREDITS AND REFERENCES

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

Thanks to Michael Novak for his work on the design of this model and the BEAGLE Evolution curriculum.

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:

COPYRIGHT AND LICENSE

Copyright 2006 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

globals
[
  leader            ;; a string expressing the player who has caught the most bugs (or a tie if appropriate)
  leader-caught     ;; the number of bugs the leader has caught
  total-caught      ;; running total of the total number of bugs caught by everyone
  adult-age         ;; the number of ticks before bugs are full grown
]

;; each client controls one player turtle
;; players are always hidden in the view
breed [players player]

players-own
[
  user-name    ;; the unique name users enter on their clients
  caught       ;; the number of bugs this user as caught
  attempts     ;; times the user has clicked in the view trying to catch a bug
  percent      ;; percent of catches relative to the leader
]

breed [bugs bug]

;; gene-frequencies determine the color
;; of each bug and mutate as bugs reproduce
bugs-own
[
  red-gene    ;; gene for strength of expressing red pigment (0-255)
  blue-gene   ;; gene for strength of expressing blue pigment (0-255)
  green-gene  ;; gene for strength of expressing green pigment (0-255)
]

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

to startup
  hubnet-reset
  setup-clear
end 

;; this kills off all the turtles (including the players)
;; so we don't necessarily want to do this each time we setup

to setup-clear
  ca
  set-default-shape bugs "moth"
  set adult-age 50
  setup
end 

;; setup the model for another round of bug catching
;; with the same group of users logged in

to setup
  cp
  clear-all-plots
  reset-ticks
  ask bugs [ die ]

  set total-caught 0
  set leader ""
  set leader-caught 0

  change-environment
  make-initial-bugs
  ;; make sure to return players to initial conditions
  ask players [ initialize-player ]
end 

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

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

to go
  grow-bugs
  reproduce-bugs
  listen-clients
  every 0.01
  [ tick ]
  do-plots
end 

to grow-bugs
  ask bugs
  [
    ;; show genotypes if appropriate, hide otherwise
    assign-genotype-labels
    ;; if the bug is smaller than bug-size then it's not full
    ;; grown and it should get a little bigger
    ;; so that bugs don't just appear full grown in the view
    ;; but instead slowly come into existence. as it's easier
    ;; to see the new bugs when they simply appear
    ifelse size < bug-size
    [ set size size + (bug-size / adult-age) ]
    [ set size bug-size ]
  ]
end 

;; keep a stable population of bugs as predation rates go up or down

to reproduce-bugs
  ;; if all the bugs are removed by predators at once
  ;; make a new batch of random bugs
  if count bugs = 0
  [ make-initial-bugs ]

  ;; otherwise reproduce random other bugs  until
  ;; you've reached the carrying capacity
  if count bugs < carrying-capacity
  [ ask one-of 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
     ;; move away from the parent slightly
     wander
   ]
end 

;;  ask all bugs to reproduce, ignoring carrying-capacity limits

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

;; used to move bugs slightly away from their parent

to wander ;; turtle procedure
   rt random 360
   fd random-float offspring-distance + 1
end 

;; loads an image as a background among the images listed in the environment chooser

to change-environment
    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
  repeat 3
  [
    ask bugs [ set color black ]
    wait 0.1
    display
    ask bugs [ set color white ]
    wait 0.1
    display
  ]
  ask bugs [ set-phenotype-color ]
end 

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 color ]
  [ set label "" ]
end 

;; convert the genetic representation of gene frequency
;; into a phenotype (i.e., a color, using the rgb primitive)
;; we are using rgb color rather than NetLogo colors, thus, we just
;; make a list of the red green and blue genes.

to set-phenotype-color  ;; turtle procedure
  set color rgb red-gene green-gene blue-gene
end 

;; imposes a threshold limit on gene-frequency.
;; without this genes could drift into negative values
;; or very large values 

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

;;;;;;;;;;;;;;;;;;;;;;
;; HubNet Procedures
;;;;;;;;;;;;;;;;;;;;;;

to listen-clients
  while [hubnet-message-waiting?]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ add-player ]
    [
      ifelse hubnet-exit-message?
     [ remove-player ]
     [
        if hubnet-message-tag = "View"
        [
          ask players with [ user-name = hubnet-message-source ]
            [ eat-bugs ]
        ]
      ]
    ]
  ]
end 

;; when a client logs in make a new player
;; and give it the default attributes

to add-player
  create-players 1
  [
    set user-name hubnet-message-source
    initialize-player
  ]
end 

to initialize-player ;; player procedure
  hide-turtle
  set attempts 0
  set caught 0
  set-percent
  send-student-info
end 

;; when clients log out simply
;; get rid of the player turtle

to remove-player
  ask players with [ user-name = hubnet-message-source ]
    [ die ]
end 

to eat-bugs
  ;; extract the coords from the hubnet message
  let clicked-xcor  (item 0 hubnet-message)
  let clicked-ycor  (item 1 hubnet-message)

  ask players with [ user-name = hubnet-message-source ]
  [
    set xcor clicked-xcor      ;; go to the location of the click
    set ycor clicked-ycor
    set attempts attempts + 1  ;; each mouse click is recorded as an attempt
                               ;; for that player

    ;;  if the players clicks close enough to a bug's location, they catch it
    ;;  the in-radius (bug-size / 2) calculation helps make sure the user catches the bug
    ;;  if they click within one shape radius (approximately since the shape of the bug isn't
    ;;  a perfect circle, even if the size of the bug is other than 1)
    let candidates bugs in-radius (bug-size / 2)
    ifelse any? candidates
    [
      let doomed-bug one-of candidates
      set caught caught + 1
      set total-caught total-caught + 1
      ask doomed-bug
        [ die ]

      ;; if a bug is caught update the leader
      ;; as it may have changed
      update-leader-stats
      ;; all the players have monitors
      ;; displaying information about the leader
      ;; so we need to make sure that gets updated
      ;; when the leader changed
      ask players
      [
        set-percent
        send-student-info
      ]
    ]
    ;; even if we didn't catch a bug we need to update the attempts monitor
    [ send-student-info ]
  ]
end 

;; calculate the percentage that this player caught to the leader

to set-percent ;; player procedure
  ;; make sure we don't get a divide by 0 error
  ifelse leader-caught > 0
  [ set percent (caught / leader-caught) * 100]
  [ set percent 0 ]
end 

;; update the monitors on the client

to send-student-info ;; player procedure
  hubnet-send user-name  "Your name" user-name
  hubnet-send user-name "You have caught" caught
  hubnet-send user-name "# Attempts"  attempts
  hubnet-send user-name "Relative %"  (precision percent 2) ;; just show 2 decimal places
  hubnet-send user-name "Top hunter" leader
  hubnet-send user-name "Top hunter's catches" leader-caught
end 

;; do the bookkeeping to display the proper leader and score

to update-leader-stats
  if any? players
  [
    let leaders players with-max [ caught ]
    let number-leaders count leaders

    ;; if there is more than one leader just report
    ;; a tie otherwise report the name
    ifelse number-leaders > 1
    [ set leader word number-leaders "-way tie" ]
    [ ask one-of leaders [ set leader user-name ] ]
    set leader-caught [caught] of one-of leaders
  ]
end 

;;;;;;;;;;;;;;;;;;;;;
;; Plotting Procedure
;;;;;;;;;;;;;;;;;;;;;

to do-plots
  set-current-plot "Bugs Caught by All Hunters vs. Time"
  plot total-caught
end 


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

There are 12 versions of this model.

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

Attached files

File Type Description Last updated
Bug Hunters Camouflage.png preview Preview for 'Bug Hunters Camouflage' over 11 years ago, by Uri Wilensky Download
glacier.jpg jpeg Glacier background over 11 years ago, by Reuven M. Lerner Download
poppyfield.jpg jpeg Poppies over 11 years ago, by Reuven M. Lerner Download

This model does not have any ancestors.

This model does not have any descendants.