【发布时间】:2016-09-12 06:02:40
【问题描述】:
我从 Google 地球中选择了一个小地图区域并将其保存为 jpg 文件。后来我把它转换成 .ppm 文件格式。然后我尝试在 NetLogo 中导入这个 .ppm 文件。但是在以下代码行中发生运行时错误“不允许使用此非标准字符(第 5 行,第 1 个字符)”,并带有文件读取
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 文件包含非数值。我正在按照汽车巡航模型的步骤进行操作。提前感谢任何帮助。
【问题讨论】: