看看这段代码的问题
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
turtles-own [a b c d k f g h
x y ;; these are the leaf-turtle's offsets relative to center-turtle
]
to new
ca
crt 5 * num_of_building
ask turtles ]
scatter ;;keep center-turtle random positions
unit_plan ;;make up the building plan
end
to scatter
ask turtles with
[
set xcor xcor - 6 + random-float 15
set ycor ycor - 6 + random-float 15
]
end
to unit_plan
ask turtles [
if (remainder who 5 = 1) [set a who
set x ( 0 - Wid / 2 )
set yDep / 2 ]
set bint (a / 5) * 5
setxy ( xcor-of turtle b + x )
( ycor-of turtle b + y )
if (remainder who 5 = 2) [set c who
set x ( 0 - Wid / 2 )
set y (0 - Dep / 2 )]
set d int (c / 5) * 5
setxy ( xcor-of turtle d + x )
(ycor-of turtle d + y )
if (remainder who 5 = 3) [set k who
set x( Wid / 2)
set y (0 - Dep / 2 ) ]
set f int (k / 5) * 5
setxy ( xcor-of turtle f + x )
(ycor-of turtle f + y )
if (remainder who 5 = 4) [set g who
set x Wid / 2
set yDep / 2 ]
set hint (g / 5) * 5
setxy ( xcor-of turtle h + x )
(ycor-of turtle h + y )
]
end
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] 已经解决了,
应该是
ask turtles [
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
set yDep / 2
set bint (who / 5) * 5
setxy ( xcor-of turtle b + x )
( ycor-of turtle b + y )]]
end
之前有个括号位置不对没发现
页:
[1]