aaa---pompeiisim2.nlogo
来自「NETLOGO」· NLOGO 代码 · 共 503 行
NLOGO
503 行
;; SUMMARY;;;; Uses color-processing to reverse-render a google map;; COPYRIGHT & LICENSE;;;; Copyright (C) 2005 James P. Steiner;;;; Some Rights Reserved.;;;; Creative Commons Attribution-NonCommercial-ShareAlike License v. 2.0.;;;; Visit http://creativecommons.org/licenses/by-nc-sa/2.0/ for more information.;; APPLET DIMENSIONS (width x height);;;; 500 x 500;; GOOGLE MAP DATA Exerpt;;;; Copyright (C) 2005 Google, Inc. ;;globals[ filename ticks]turtles-own[heard-it? ;; yes or no variabletimes-heard-it ;; count of how many times a turtle has encountered another who passes on the 'message'] to go set ticks ticks + 1 let side-look-scaling 1 ;; make bigger for higher-res maps every .02 [ ifelse ( pcolor-of patch-left-and-ahead 45 2 = brown and pcolor-of patch-right-and-ahead 45 2 != brown ) [ rt 15 ][ if ( pcolor-of patch-right-and-ahead 45 2 = brown and pcolor-of patch-left-and-ahead 45 2 != brown ) [ lt 15 ] ] ifelse ( pcolor-of patch-ahead .5 = brown ) [ rt random-one-of [ -135 -90 -45 45 90 135 180 ] ] [ let turns (list patch-left-and-ahead 90 (7 * side-look-scaling) patch-right-and-ahead 90 (7 * side-look-scaling) ) set turns filter [ pcolor-of ?1 = white ] turns if turns != [] and random 10 = 0 [ set turns random-one-of turns set heading towards turns ] jump .5 ] ] if proselytize? and color-of self = blue [ let target random-one-of turtles in-radius 15 with [ not heard-it?] if target != nobody and target != self [ set heading towards target ] ] pass-the-word update-plots if everyone-heard-it = 100 [stop]endto pass-the-wordask turtles with [heard-it?] [ ask other-turtles-here with [ not heard-it? ] [ if (random-float 100) < importance-of-the-news [ get-the-word ] ] ]endto get-the-word ;; turtle procedure set heard-it? true set color blueendto-report everyone-heard-itreport (((count turtles with [ color = blue]) / ( count turtles )) * 100)end;;;;plots;;;;to update-plotsupdate-message-diffusionendto update-message-diffusion set-current-plot "Message Diffusion Over Time" set-current-plot-pen "%hearing" plot ( ((count turtles with [ color = blue]) / ( count turtles )) * 100 )end;;;;;setup;;;;to setup ca set ticks 0 let known-paths [ "./" "./models/" "./images/" "../models/" "../images/" ] let basename map-name let paths-to-try length known-paths set filename false let index 0 while [ index < paths-to-try ] [ if file-exists? (word (item index known-paths) basename) [ set filename (word (item index known-paths) basename) set index paths-to-try ] set index index + 1 ] if filename = false [ set filename user-choose-file ] if filename = false [ stop ] import-pcolors filename pause ask patches [ ;; set pcolor pcolor - pcolor mod 10 + 5 if pcolor = 7.9 [ set pcolor brown ] ] pause ask patches [ ;; set pcolor pcolor - pcolor mod 10 + 5 if shade-of? pcolor brown [ set pcolor brown ] ] pauseask patches [ ;; set pcolor pcolor - pcolor mod 10 + 5 if not shade-of? pcolor brown [ set pcolor white ] ] pauseask patches [ let c count neighbors with [ pcolor = white] if c >= 6 and c <= 8 [ set pcolor white ] ] pause ask patches with [ pcolor = brown] [ if any? neighbors with [ pcolor = white ] [ let shade count neighbors with [ pcolor = white ] set pcolor brown + (shade / 8) * 5 ] ] pauseask patches with [ (abs pxcor = screen-edge-x ) or ( abs pycor = screen-edge-y ) ] [ set pcolor brown ] pause load-overlay ask random-n-of 10 patches with [ pcolor = white ] [ sprout 1 + random 5 [ set size 4 set shape "person" set label who set label-color black set heard-it? false set color black ] ]ask turtle 0 [jump .2 set color blue set heard-it? true ] endto clear-half-overlay ;; the drawing layer is selectively erased to reveal the underlying patch colors ;; since the drawing pen is 1 pixel, but the patches can be many pixels, ;; and since there is no way for a model to know how many pixels wide the patches are ;; this routine uses a kludge: ;; Theoretically, a turtle draws a series of squares of decending size, ;; erasing a 1 pixel line as it goes. The squares reduce in size by only a fraction of ;; the patch, thus erasing all the pixels of the patch. ;; In Practical terms, things are faster if you draw fewer lines using a fatter pen. ;; So, pixels-per-patch is 3 (for 5 pixel patches) and overdraw is also three. ;; The beauty of this method is that it does not break when the model ;; pixels-per-patch is changed slightly, so it balances flexibility with speed. ;; NOTE: to accomodate diagonal wiping, some overdrawing is required! ;; it ends up missing bits on larger patches, and over-erasing smaller ones. ;; change the local variable "pixels-per-patch" and overdraw to adjust this ;; procedure ;; for different patch sizes. let pixels-per-patch 3 let overdraw 3 let decrement 1 / pixels-per-patch cct 1 [ home set heading 0 let stroke 0 set pen-size overdraw pe repeat 2 [ set stroke screen-edge-y + (decrement * .5 * (pixels-per-patch - 1)) ;; from 0 to exact edge, must go 1/2 patch more! repeat 3 [ jump stroke rt 90 ] repeat pixels-per-patch * screen-edge-y [ set stroke stroke - decrement repeat 2 [ jump stroke rt 90 ] ] home set heading 180 ] die ] endto clear-half-overlay-2 cct 1 [ hide-turtle set color black set pen-size 5 setxy screen-edge-x screen-edge-y set heading 180 pe let stroke screen-size-y let decrement 2 * screen-size-x / screen-size-y let way 1 repeat screen-size-x [ jump stroke rt 135 * way jump 1.4 setxy pxcor pycor rt 45 * way set stroke stroke - decrement set way way * -1 ] die ]end to load-overlay import-drawing filenameendto clear-overlay clear-drawingendto pause if slow-conversion? [ wait 2 ]end @#$#@#$#@GRAPHICS-WINDOW19410731443105802.5151110001CC-WINDOW54571025552Command Center0BUTTON4106743NILsetupNIL1TOBSERVERTNILBUTTON4496782NILgoT1TTURTLENILNILSWITCH2182159215slow-conversion?slow-conversion?11-1000BUTTON1215131248NILclear-half-overlayNIL1TOBSERVERTNILBUTTON1247131280NILclear-half-overlay-2NIL1TOBSERVERTNILBUTTON-1311129344NILload-overlayNIL1TOBSERVERTNILSWITCH-5347191380load-overlay-with-setup?load-overlay-with-setup?11-1000SLIDER731409917442importance-of-the-newsimportance-of-the-news110010011NILPLOT731101016260Message Diffusion Over Timetime% who've heard0.010.00.010.0truefalsePENS"%hearing" 1.0 0 -16777216 trueMONITOR1291218661NILticks31BUTTON1279167312clear overlay completelycdNIL1TOBSERVERTNILSWITCH731279855312proselytize?proselytize?01-1000BUTTON732338855371Track MovementpdNIL1TTURTLETNILCHOOSER493160138map-namemap-name"falerii.png" "pompeii.png"1@#$#@#$#@SUMMARY BY SHAWN GRAHAM----------------This model marries the information diffusion procedure from my itineraries.nlogo to thegoogle-maps-import.nlogo model developed by James Steiner; his summary for the map import model is below. I've swapped a Google Map for a map of Pompeii. Other ancient cities could be similarlyadded, by creating a map chooser and pre-processing the maps so that they use the similar color schemes a la Google Maps.I've also added 'intentionality' to this model. If the proselytize switch is 'on', agents who have heard the message actively seek out agents who haven't, and tell them the message. It could be extended further by allowing agents to actively contest ideas.What does this show? The fabric of a town, by allowing different patterns of interaction, has an impact on how life was lived in that town. With different base maps, one could compare the rates of information diffusion with and without intentionality for the different towns. That is, information diffusion would be an indicator by which the effects of different town layouts had on the way life was lived in those places. In terms of archaeology, these simulations would also suggest places of intensification in the towns. The patterns of movements would have an impact on what we find archaeologically.The 'track movement' button causes agents to leave a trail of their travels. With this pressed, one can view which regions of the town seem to have the heaviest travel patterns.'Importance of the News' ie the relative chance that an encounter will lead to transmission of information.I would appreciate an email if anybody decides to adapt/expand this model; credit for the original model should be to James Steiner, www.turtlezero.com. Shawn GrahamSUMMARY BY JAMES STEINER--------------------------------------------------------------------------------A map image is imported and automatically converted back into navigable layer data.WHAT IS IT?-----------This model imports a small but hi-res PNG image that is a section of a google map into the low-res pcolors. Then, using assumptions about how google maps are colored, and how those colors translate into netlogo colors, the map colors are cleaned up and reduced, then the colors are used to assign simple land-use codes to the patches: roadway, road-edge, non-roadway.Using this information, some turtles are put on the map and navigate it randomly.Additionally, the original png map can be loaded into the drawing layer as an overlay. So, the turtles navigate the map using the low-res data, but visually we can see the hi-res data.COPYRIGHT--------------------------------------------------------------------------------Copyright
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?