1
中所做的那樣,我從Google Earth中選擇了一個小地圖區域並將其保存爲jpg文件。後來我將它轉換成.ppm文件格式。然後我試圖在NetLogo中導入這個.ppm文件。但發生運行時錯誤「這種非標準字符是不允許的(行號5,字符1)」與文件讀取在下面的代碼線關於在netlogo中導入.ppm文件格式,如在巡航模型
ask patches [
set pcolor rgb (file-read/256) (file-read/256) (file-read/256)
]
下面是我轉換爲.ppm格式的JPG (便攜式像素地圖)文本圖形格式。
我做的代碼是
globals [
mapname
]
to startup ; slow, do just once
init-map
end
to init-map
set mapname "sangamarea"; set mapname "cruise"
create-dat mapname
end
to create-dat [mapfile]
print "..creating patches, I'll print 'done' when completed"
import-ppm mapfile
export-dat mapfile
print "..done!"
end
to import-ppm [ppmfile]
let x 0 let y 0 let scale 0 ;locals [x y scale]
set ppmfile (word ppmfile ".ppm")
file-close-all
file-open ppmfile
set x 1 set y file-read-line
while [first file-read-line = "#"] [set x x + 1]
file-close
file-open ppmfile
repeat x [set x file-read-line]
set x file-read
set y file-read
set scale 1 + file-read
if x != random-xcor and y != random-ycor [print "Oops: need to fix screen-size to match ppm file"]
ask patches [set pcolor rgb (file-read/256) (file-read/256) (file-read/256)]
file-close
cleanup-map
end
to cleanup-map
ask patches with [(floor pcolor) mod 10 = 9] [set pcolor 9.9]
ask patches with [pcolor != 9.9] [set pcolor round pcolor]
ask patches with [pcolor > 120] [set pcolor pcolor - 110]
end
to export-dat [datfile]
set datfile word datfile ".dat"
file-close-all
if file-exists? datfile [file-delete datfile]
file-open datfile
ask patches [file-write floor pcolor if pxcor = max-pxcor [file-print ""]] ;screen-edge-x
file-close
end
我不明白爲什麼錯誤是,我的JPEG圖像是大尺寸,或者可以.ppm格式文件包含非數值。我遵循汽車巡航模型的步驟。提前感謝任何幫助。
好的,謝謝先生。 –