---basic_daisyworld_random.nlogo

来自「NETLOGO」· NLOGO 代码 · 共 885 行 · 第 1/2 页

NLOGO
885
字号
globals[ ;;all of the areas are in percent of screen a_b   ;area covered by black daisies a_w   ;area covered by white daisies a_un  ;area of barren land ; Al_b   ;albedo of black daisies; Al_w   ;albedo of white daisies; Al_un  ;albedo of barren land Al_p   ;albedo of whole planet  g_w   ;growth factor of white daisies g_b   ;growth factor of black daisies  T_p   ;planetary temperature T_b   ;temperature around black daisies T_w   ;temperature around white daisies T_dead;temperature of a dead planet  F_HA  ;heat absorption factor ;death-rate SB_const ;Stefan-Boltzmann constant SF_const ;solar flux constant ;SL       ;solar luminosity worldarea;area of the world  time     ;counter of time  success ;global for communicating with patches ]patches-own[  status?]to initca;;set up areasset a_un 1set a_b  0set a_w  0;;initialize albedosset Al_un 0.5set Al_b  0.25set Al_w  0.75set Al_p  0.5 ;no daisies ;;initalise ideal temperatures for daisies;set idealblacktemp 22;set idealwhitetemp 22;;initialize constantsset F_HA 20set death-rate 0.3set SB_const 5.669e-8;W/degK^4set SF_const 917;W/m^2;;initalize temperature and solar luminosityset SL 0.6set T_dead (((SL * SF_const * (1 - Al_p) / SB_const) ^ 0.25 ) - 273) ;temperature of a dead planet (degC)ifelse(autotemp)[set T_p T_dead][set T_p 20set SL 0.6]set time 0set worldarea 4 * ( screen-edge-x + 1 ) * (screen-edge-y + 1)ask patches[set status? "barren"]endto iterate;;recalculate luminosity and global tempif(autotemp)[ set SL (0.6 + (time * (0.001))) ] ;recalculate luminosityifelse(a_un < 1)[set T_p ((SL * SF_const * (1 - Al_p) / SB_const) ^ 0.25) - 273 ;recalculate global temperature][set T_p (((SL * SF_const * (1 - 0.5) / SB_const) ^ 0.25 ) - 273) ;temperature of a dead planet (degC)]set T_dead (((SL * SF_const * (1 - 0.5) / SB_const) ^ 0.25 ) - 273) ;temperature of a dead planet (degC);;recalculate local temperaturesset T_b (F_HA * (Al_p - Al_b) + T_p)set T_w (F_HA * (Al_p - Al_w) + T_p)set g_b (1 - 0.003265 * ((idealblacktemp - T_b) ^ 2))set g_w (1 - 0.003265 * ((idealwhitetemp - T_w) ^ 2))grow-daisieslet da_b a_b * (a_un * g_b - death-rate) + 0.01let da_w a_w * (a_un * g_w - death-rate) + 0.01;;recalculate planetary albedo and areas set a_b (count patches with[status? = "black"]) / worldareaset a_w (count patches with[status? = "white"]) / worldareaset a_un 1 - a_b - a_wset Al_p ((a_un) * (Al_un) + (a_b) * (Al_b) + (a_w) * (Al_w));;increment time, color daisiesset time (time + 1)ask patches[color-daisies]set-current-plot "Daisies"set-plot-pen-interval 1set-current-plot-pen "black"plot a_bset-current-plot-pen "white"plot a_wset-current-plot-pen "barren"plot a_unset-current-plot "Temperature"set-plot-pen-interval 1set-current-plot-pen "temp"plot T_pset-current-plot-pen "temp-without-daisies"plot T_dead;file-open "c:\\daisyms.out";file-write time;file-write a_b file-write a_w file-write a_un file-write T_p file-write T_dead;file-print " ";file-closeendto grow-daisiesif(a_b = 0) and (g_b > 0)[start-new-black-patch]if(a_w = 0) and (g_w > 0)[start-new-white-patch]let da_b a_b * (a_un * g_b - death-rate) + 0.001let da_w a_w * (a_un * g_w - death-rate) + 0.001ifelse(da_b > 0)[ask patches with[status? = "black"] [ grow-black-daisies ]][ask patches with[status? = "black"] [if(random-float 1 < (- da_b))[set status? "barren"]]]ifelse(da_w > 0)[ask patches with[status? = "white"] [ grow-white-daisies ]][ask patches with[status? = "white"] [if(random-float 1 < (- da_w))[set status? "barren"]]]endto grow-black-daisieslet numblack (count patches with[status? = "black"]) let da_b a_b * (a_un * g_b - death-rate) + 0.001set da_b da_b *  (100 / 8)ifelse (count neighbors with [not (status? = "barren")] > spread-thresh )[ if(random-float 1 < da_b) [start-new-black-patch]][  ask neighbors   [  if(random-float 1 < da_b and status? = "barren")  [  set status? "black"  ]    ]]endto grow-white-daisieslet numwhite (count patches with[status? = "white"]) let da_w a_w * (a_un * g_w - death-rate) + 0.001set da_w da_w * (100 / (8))ifelse (count neighbors with [not (status? = "barren")] > spread-thresh )[if(random-float 1 < da_w) [start-new-white-patch]][  ask neighbors   [  if(random-float 1 < da_w and status? = "barren")  [  set status? "white"  ]    ]]endto start-new-black-patchset success false  ;;pick a random x coordinate  let currxcor (random (2 * screen-edge-x)) - screen-edge-x  ;;pick a random y coordinate  let currycor (random (2 * screen-edge-y)) - screen-edge-y  ask patches with[ pxcor = currxcor and pycor = currycor and status? = "barren"]  [    set status? "black"    set success true  ]  ifelse (success)  [    ;;do nothing  ]  [    start-new-black-patch  ]endto start-new-white-patchset success false  ;;pick a random x coordinate  let currxcor (random (2 * screen-edge-x)) - screen-edge-x  ;;pick a random y coordinate  let currycor (random (2 * screen-edge-y)) - screen-edge-y  ask patches with[ pxcor = currxcor and pycor = currycor and status? = "barren"]  [    set status? "white"    set success true  ]  ifelse (success)  [    ;;do nothing  ]  [    start-new-white-patch  ]endto color-daisiesifelse (status? = "black")[set pcolor black][  ifelse (status? = "white")  [  set pcolor white  ]  [  set pcolor brown  ]]end@#$#@#$#@GRAPHICS-WINDOW2076152239730305.01101110111CC-WINDOW5485784580Command Center0BUTTON4521651549NILinit\nNIL1TOBSERVERTNILMONITOR6081168260Black Areaa_b\n31MONITOR6881076359White Areaa_w31MONITOR434408517457Planet Temp.T_p31PLOT53061775263DaisiesNILNIL0.010.00.01.0truefalsePENS"black" 1.0 0 -16777216 true"white" 1.0 0 -5325092 true"barren" 1.0 0 -6459832 truePLOT531268775471Temperaturetime ->Temperature (C)0.010.0-20.0100.0truefalsePENS"temp" 1.0 0 -10899396 true"temp-without-daisies" 1.0 0 -6459832 trueBUTTON3751644149NILiterate\nT1TOBSERVERTNILSLIDER232219555idealblacktempidealblacktemp01002211NILSLIDER235919592idealwhitetempidealwhitetemp01002211NILSLIDER25117197150Al_wAl_w010.750.01

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?