;; 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 ] to go 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 ][ ifelse ( [pcolor] of patch-right-and-ahead 45 2 = brown and [pcolor] of patch-left-and-ahead 45 2 != brown ) [ lt 15 ][ set color green ] ] ifelse ( [pcolor] of patch-ahead .5 = brown ) [ set color orange rt 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 one-of turns set heading towards turns ] jump .5 ] ] end to setup ca let known-paths [ "./" "./models/" "./images/" "../models/" "../images/" ] let basename "north40thmap.png" 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-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 ] ] pause ask patches [ ;; set pcolor pcolor - pcolor mod 10 + 5 if not shade-of? pcolor brown [ set pcolor white ] ] pause ask patches [ let c count neighbors with [ pcolor = white] if c >= 5 and c <= 7 [ 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 ] ] pause ask patches with [ (abs pxcor = max-pxcor ) or ( abs pycor = max-pycor ) ] [ set pcolor brown ] pause if load-overlay-with-setup? [ load-overlay ] ask n-of 10 patches with [ pcolor = white ] [ sprout 1 [ set size 4 set color green set shape "circle" set label who set label-color black ] ] end to 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 crt 1 [ home set heading 0 let stroke 0 set pen-size overdraw pe repeat 2 [ set stroke max-pycor + (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 * max-pycor [ set stroke stroke - decrement repeat 2 [ jump stroke rt 90 ] ] home set heading 180 ] die ] end to clear-half-overlay-2 crt 1 [ hide-turtle set color black set pen-size 5 setxy max-pxcor max-pycor set heading 180 pe let stroke world-height let decrement 2 * world-width / world-height let way 1 repeat world-width [ 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 filename end to clear-overlay clear-drawing end to pause if slow-conversion? [ wait 2 ] end @#$#@#$#@ GRAPHICS-WINDOW 183 10 698 546 50 50 5.0 1 10 1 1 1 0 1 1 1 -50 50 -50 50 0 0 1 ticks BUTTON 9 49 72 82 NIL setup NIL 1 T OBSERVER NIL NIL NIL NIL BUTTON 9 88 72 121 NIL go T 1 T TURTLE NIL NIL NIL NIL BUTTON 29 169 160 202 NIL clear-half-overlay NIL 1 T OBSERVER NIL NIL NIL NIL BUTTON 29 206 160 239 NIL clear-overlay NIL 1 T OBSERVER NIL NIL NIL NIL BUTTON 29 133 160 166 load high-res overlay load-overlay NIL 1 T OBSERVER NIL NIL NIL NIL SWITCH 9 10 179 43 load-overlay-with-setup? load-overlay-with-setup? 1 1 -1000 SWITCH 8 261 165 294 slow-conversion? slow-conversion? 0 1 -1000 @#$#@#$#@ SUMMARY -------------------------------------------------------------------------------- A map image captured from Google Maps is imported and automatically converted 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 © 2005,2009 James P. Steiner. Google Maps Image Copyright © 2005 Google, Inc. @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 circle false 5 Circle -10899396 true true 0 0 300 square false 5 Rectangle -10899396 true true 0 0 300 300 @#$#@#$#@ NetLogo 4.1beta1 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ default 0.0 -0.2 0 1.0 0.0 0.0 1 1.0 0.0 0.2 0 1.0 0.0 link direction true 0 Line -7500403 true 150 150 90 180 Line -7500403 true 150 150 210 180 @#$#@#$#@ 0 @#$#@#$#@