📄 ---pepperedmothsd.nlogo
字号:
;; ***** Pepper Moth Phenotyphic Population Change *****breeds [ moths eggs ]moths-own [ age ;; moth's age: Lifespan is approximately 4 days alleles ;; Moth type: 0 = AA , 1 = Aa , 2 = aa gender ;; Moth gender: 0 = Male, 1 = Female mated? ;; Has the moth mated? ]eggs-own [ alleles ] ;; What alleles does the egg have? (random gender)globals [ years ticks ;; time tick-pollute ;; time unit for historical-pollution purposes tick-pollute2 ;; time unit for historical-pollution purposes light-moths ;; number of light colored moths dark-moths ;; number of dark colored moths total ;; number of eggs darkness ;; darkness (pollution) level in the world darkening? ;; is the world getting darker (more polluted)? - true or false];; reports color value that reflects current pollution level.;; 1 = black. 9 = white. color = white - darkness. darkness range: 0 - 8. color range: 1 - 9.to-report env-color report 9 - darknessend;; reports numerical color change value that reflects user's speed % choice.to-report delta-env report (speed / 100)end;; generates random color integers in black-white range (1-9);;to-report random-color ;;report (ifelse ((random 2 = 0))[set color 9][set color 0]);;end;; reports maximum moth population for a given environmentto-report upper-bound report (4 * num-moths)endto setup ca setup-world setup-moths setup-plotting update-monitors update-plotsendto setup-world set years 1800 set ticks 0 set darkness 0 set darkening? true ;; world starts out clean - can only get polluted ask patches [ set pcolor env-color ]endto setup-moths ifelse historical-pollution? [ create-custom-moths num-moths [ set gender (random 2) ;; random genders set mated? false set age (random 3) ;; start out with random ages ifelse ((random 27) = 0) [ifelse ((random 2) = 0) [set alleles 0] [set alleles 1] ] [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 num-moths [ set gender (random 2) ;; random genders set mated? false set age (random 3) ;; start out with random ages set alleles (random 3) ;; 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 ]]endto setup-plotting set-current-plot "Moth Colors Over Time" set-plot-y-range 0 upper-boundendto go set ticks (ticks + 1) if (ticks = 5) [set years (years + 1)] if (ticks = 5) [set ticks (ticks - 5)] if ((light-moths + dark-moths) < 1) [ eggs-hatch ] update-monitors update-plots ask moths [ moths-mate moths-grim-reaper moths-get-eaten moths-age moths-move ] if historical-pollution? [ ;; Activates Historical Pollution historical-pollution set tick-pollute2 (tick-pollute2 + 1) ] if cycle-pollution? [ cycle-pollution ] moths-black ;; immigration moths-white ;; immigration endto eggs-hatch wait 2 ask eggs [ hatch0 hatch1 hatch2 die ] black-hatchendto black-hatch if ( (100 * darkness / 8) > 45) [create-custom-moths ((150 / num-moths) * (100 * darkness / 8)) [ 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 ] ]endto hatch0 if (alleles = 0) [ if ((random total) < upper-bound) [ hatch 1 [ set breed moths set color 0 set gender (random 2) set alleles (0) set mated? false set age 0 moths-pick-shape rt random 360.0 fd 2 ;; move away from your parent so you can be seen ]]] endto hatch1 if (alleles = 1) [ if ((random total) < upper-bound) [ hatch 1 [ set breed moths set color 0 set gender (random 2) set alleles (1) set mated? false set age 0 moths-pick-shape rt random 360.0 fd 2 ;; move away from your parent so you can be seen ]]]endto hatch2 if (alleles = 2) [ if ((random total) < upper-bound) [ hatch 1 [ set breed moths set color 9 set gender (random 2) set alleles (2) set mated? false set age 0 moths-pick-shape rt random 360.0 fd 2] ;; move away from your parent so you can be seen ]] endto moths-mate ifelse ((count moths) > upper-bound) [] ;; Resource Scarcity = No Reproduction [ moths-mate00 moths-mate01 moths-mate02 moths-mate10 moths-mate11 moths-mate12 moths-mate20 moths-mate21 moths-mate22 ]end to moths-mate00 ;; moth procedure ifelse ( (100 * darkness / 8) < 60 ) [ ifelse ( (100 * darkness / 8) < 40 ) [] [ if (( random 3 ) = 0) [ mate00 ] ] ] [mate00]end to mate00 ;; moth procedure if ((gender = 1) and (alleles = 0) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 0) ] > 0 ) [ hatch (moth-growth + 1) [ set breed eggs set alleles (0) eggs-shape rt random 360.0 fd 2 ;; move away from your parent so you can be seen ] set mated? true ] ] end to moths-mate01 ;; moth procedure ifelse ( (100 * darkness / 8) < 60 ) [ ifelse ( (100 * darkness / 8) < 40 ) [] [ if (( random 3 ) = 0) [ mate01 ] ] ] [mate01]end to mate01 ;; moth procedure if ((gender = 1) and (alleles = 0) 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 0 ] [ 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-mate02 ;; moth procedure ifelse ( (100 * darkness / 8) < 60 ) [ ifelse ( (100 * darkness / 8) < 40 ) [] [ if (( random 3 ) = 0) [ mate02 ] ] ] [mate02]end to mate02 ;; moth procedure if ((gender = 1) and (alleles = 0) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 0) ] > 0 ) [ hatch moth-growth [ set breed eggs set alleles (1) eggs-shape rt random 360.0 fd 2 ;; move away from your parent so you can be seen ] set mated? true ] ] endto moths-mate10 ;; moth procedure ifelse ( (100 * darkness / 8) < 60 ) [ ifelse ( (100 * darkness / 8) < 40 ) [] [ if (( random 3 ) = 0) [ mate10 ] ] ] [mate10]end to mate10 ;; moth procedure if ((gender = 1) and (alleles = 1) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 0) ] > 0 ) [ hatch (moth-growth + 1) [ set breed eggs eggs-shape ifelse ((random 2 = 0)) [ set alleles 0 ] [ set alleles 1 ] rt random 360.0 fd 2 ;; move away from your parent so you can be seen ] set mated? true ] ] end to moths-mate11 ;; moth procedure if ((gender = 1) and (alleles = 1) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 1) ] > 0 ) [ hatch moth-growth [ set breed eggs eggs-shape ifelse ((random 2 = 0)) [ set alleles 1 ] [ ifelse ((random 2 = 0)) [set alleles 0 ] [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-mate12 ;; moth procedure ifelse ( (100 * darkness / 8) < 10 ) [] [mate12]end to mate12 ;; moth procedure if ((gender = 1) and (alleles = 1) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 2) ] > 0 ) [ hatch moth-growth [ set breed eggs eggs-shape ifelse ((random 2 = 0)) [ set alleles 1 ] [ 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-mate20 ;; moth procedure if ((gender = 1) and (alleles = 2) and (mated? = false) ) [ if (count moths in-radius 1 with [ gender = 0 and (alleles = 0) ] > 0 ) [ hatch moth-growth [ set breed eggs 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -