📄 ---pepperedmothsd.nlogo
字号:
to moths-mate21 ;; moth procedure ifelse ( (100 * darkness / 8) < 10 ) [ ] [mate21]end to mate21 ;; moth procedure if ((gender = 1) and (alleles = 2) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 1) ] > 0 ) [ hatch moth-growth [ set breed eggs ifelse ((random 2 = 0)) [ set alleles 2 ] [ set alleles 1 ] eggs-shape rt random 360.0 fd 2 ;; move away from your parent so you can be seen ] set mated? true ] ] end to moths-mate22 ;; moth procedure ifelse ( (100 * darkness / 8) > 65 ) [ ifelse ( (100 * darkness / 8) > 85 ) [] [ if (( random 3 ) = 0) [ mate22 ] ] ] [mate22]end to mate22 if ((gender = 1) and (alleles = 2) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 2) ] > 0 ) [ hatch (moth-growth + 1) [ set breed eggs eggs-shape set alleles (2) rt random 360.0 fd 2 ;; move away from your parent so you can be seen ] set mated? true ] ] end to moths-black if ( (dark-moths + light-moths) > 50 ) [ ifelse ( (100 * darkness / 8) > 45 ) [ if ((random 2) = 0) [ create-custom-moths 5 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (random 2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] ][ if ( (100 * darkness / 8) < 45 ) [ ifelse ((random 4) = 0) [ create-custom-moths 3 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (random 2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] [ create-custom-moths 1 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (random 2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] ]] ] end to moths-white if ((dark-moths + light-moths) > 50) [ ifelse ( (100 * darkness / 8) < 65 ) [ if ((random 2) = 0) [ create-custom-moths 5 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] ] [ if ( (100 * darkness / 8) > 65 ) [ ifelse ((random 4) = 0) [ create-custom-moths 3 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] [ create-custom-moths 1 [ set gender (random 2) ;; random genders set mated? false set age (random 0) ;; start out with random ages set alleles (2) ;; random type ifelse ( alleles = 2) [set color 9] [set color 0] moths-pick-shape setxy (random screen-size-x) (random screen-size-y) ;; values beyond the edge of the screen get wrapped ] ] ]]] end ;; we have a range of 'well-camouflaged-ness', dependent on the rate of selectionto moths-get-eaten ;; moth procedure if (random 1000.0 < (selection * (abs (env-color - color))) + 0) [ die ]end;; disease, children, entomologists, etc...;; the moth's world is a cruel place.to moths-grim-reaper ;; moth procedure if ((random 13) = 0) [ die ] if ( age > 3 ) [ if ((random 2) = 0) [ die ]] ;; Lifespan Exceeded ;; population overshoot / resource scarcity if ((count moths) > upper-bound) [ ifelse ((random 4) = 0) [if ((count moths) > (upper-bound * 2)) [die] ] [die] ] ;; Dominant Allele Control if ((count moths) > (upper-bound / 4)) [ ifelse (alleles = 2) [] [if ((random 2) = 0) [ die ] ] ] ;; Emigration if ((count moths) > (upper-bound * 3 / 4 )) [ if ((random 6) = 0) [ die] ] endto moths-age ;; moth procedure set age (age + 1)endto moths-move if (gender = 0) [ fd 1]endto eggs-shape set shape "egg"end to moths-pick-shape ;; moth procedure ifelse (color < 5 ) [ set shape "moth-dark2" ][ set shape "moth-light2" ]end to update-monitors ;; colors range from 1 - 9. dark moths = 1-3. medium moths = 4-6. light moths = 7-9. set total (count eggs) set light-moths (count moths with [color >= 7]) set dark-moths (count moths with [color <= 3]) endto update-plots set-current-plot-pen "Light" plot light-moths set-current-plot-pen "Dark" plot dark-moths set-current-plot-pen "Pollution" plot ((100 * darkness / 8))end;; single pollution step. called by cycle-pollution. can also be invoked by "pollute" button.to pollute-world ifelse (darkness <= (8 - delta-env)) [ ;; can the environment get more polluted? set darkness (darkness + delta-env) ask patches [ set pcolor env-color ] ][ set darkening? false ]end;; single de-pollution step. called by cycle-pollution. can also be invoked by "clean up" button.to clean-up-world ifelse (darkness >= (0 + delta-env)) [ ;; can the environment get cleaner? set darkness (darkness - delta-env) ask patches [ set pcolor env-color ] ][ set darkening? true ]end;; world dims, then lightens, all in lockstep;; a monochrome world is best for this, because otherwise it'd be very;; difficult to tell what is a moth and what is a patchto cycle-pollution ifelse (darkening? = true) [ pollute-world ][ clean-up-world ]end;; This is the historical population patterns that occured in Britain during The 19th-20th Century.to historical-pollution if (tick-pollute2 > 9) and (tick-pollute2 < 1000) [ ifelse (darkening? = true) [pollute-world] [ set tick-pollute (tick-pollute + 1) lull-period ] ]endto lull-period if (tick-pollute > 50) [clean-up-world2]end;; This reflects the much faster shift from polluted to non-polluted in Britain;; after pollution laws were set.to clean-up-world2 if (darkening? = false) [ ifelse (darkness >= (0 + (delta-env * 5))) [ ;; can the environment get cleaner? set darkness (darkness - (delta-env * 5)) ask patches [ set pcolor env-color ] ][ set darkness 0 set darkening? true set tick-pollute2 1000 ] ]end ; *** Edited by Alan Sun, Shodor Foundation 2003 ***;; This model has been changed drastically to reflect a more accurate model of the; actual fluctuations of the Pepper Moths due to pollution. Instead of large mutations,; color is based realistically on the alleles of the moths. The moths actually mate, ; instead of asexual reproduction, and also are split into seperate genders.; Now, only light and dark moths remain, to reflect the recessive and dominant phenotypes; of the Pepper Moths. Another new factor is Immigration and Emigration of Moths of; both phenotypes as the wind carries them to differing areas. Finally , this model; also contains a switch to activate the historical pattern of pollution in Britain in ; the 19th to 20th centuries. It shows a gradual climb of pollution, then a brief period of ; very high levels of pollution, ending with a swift decline of pollutioin after the ; laws governing pollution were put in place.; *** NetLogo Model Copyright Notice ***;; This model was created as part of the project: CONNECTED MATHEMATICS:; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL; MODELS (OBPML). The project gratefully acknowledges the support of the; National Science Foundation (Applications of Advanced Technologies; Program) -- grant numbers RED #9552950 and REC #9632612.;; Copyright 1998 by Uri Wilensky. All rights reserved.;; Permission to use, modify or redistribute this model is hereby granted,; provided that both of the following requirements are followed:; a) this copyright notice is included.; b) this model will not be redistributed for profit without permission; from Uri Wilensky.; Contact Uri Wilensky for appropriate licenses for redistribution for; profit.;; This model was converted to NetLogo as part of the project:; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN; CLASSROOMS. The project gratefully acknowledges the support of the; National Science Foundation (REPP program) -- grant number REC #9814682.; Converted from StarLogoT to NetLogo, 2001. Updated 2002.;; To refer to this model in academic publications, please use:; Wilensky, U. (1998). NetLogo Peppered Moths model.; http://ccl.northwestern.edu/netlogo/models/PepperedMoths.; Center for Connected Learning and Computer-Based Modeling,; Northwestern University, Evanston, IL.;; *** End of NetLogo Model Copyright Notice ***@#$#@#$#@GRAPHICS-WINDOW30210680409171710.514311000CC-WINDOW10360297480Command CenterSLIDER21206279239num-mothsnum-moths025020011NILPLOT68448984335Moth Colors Over TimeTimeMoth Color Count0.0200.00.0850.0falsetruePENS"Light" 0.2 0 -16711936 true"Dark" 0.2 0 -16776961 true"Pollution" 0.2 0 -16777216 trueBUTTON11326665setupsetupNIL1TOBSERVERMONITOR698348792397Light Moths %100 * light-moths / (light-moths + dark-moths)21MONITOR840347933396Dark Moths %100 * dark-moths / (light-moths + dark-moths)21BUTTON723212865gogoT1TOBSERVERMONITOR
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -