|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 c/ G8 y! }- q$ v$ }4 F- ?! }! Q" L9 W: u/ m8 N2 c
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- H' ?' V @) G7 b" n3 a0 b: o
$ w* u2 u6 {; {5 ?* mturtles-own [a b c d k f g h
4 W" P/ Q5 c* w$ D x y ;; these are the leaf-turtle's offsets relative to center-turtle
$ e3 V1 j/ j% K" V]
1 C; k j+ W5 O& q7 Q$ _; M, }9 [to new
0 L ]' m4 Z+ h) R ca" b2 p$ @1 K7 ~
crt 5 * num_of_building
5 J& `+ \' f- m: N6 h ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]& s- `; a3 m% d( @5 C3 u
scatter ;;keep center-turtle random positions
5 U7 x1 m; E/ P5 E8 t unit_plan ;;make up the building plan8 u; P" Y& q. l" |4 q" a" o
end& O% S% J0 f( A* p
to scatter: w7 l6 x9 o( L, z( ^7 }
ask turtles with [remainder who 5 = 0]
4 Y; C$ w; |+ i[
/ l. D3 i7 X. a0 Uset xcor xcor - 6 + random-float 15! O# t' y G& t
set ycor ycor - 6 + random-float 15, s7 z! |9 ^8 w p; D+ c; Q
]3 r: o; Y. B c0 o0 ], R! h
end
7 S* r P" j) Sto unit_plan / k) Q$ V: Z' W! k: ]# c) @* G
ask turtles [
( H4 }. N) `$ O1 nif (remainder who 5 = 1) [set a who
- b* q& H9 Y' y: @, a3 X set x ( 0 - Wid / 2 )
8 X9 I. U1 ?* i/ i set y Dep / 2 ]
# l' R8 B J, E set b int (a / 5) * 5
. p+ V& e! D' _ setxy ( xcor-of turtle b + x )
$ x8 a, W- h5 o- v N; G ( ycor-of turtle b + y )" N1 ^) w+ x% e! n
if (remainder who 5 = 2) [set c who
8 t* p6 u' Z. v/ B9 A K set x ( 0 - Wid / 2 )
3 R; T3 X' x1 P1 b7 F+ w set y (0 - Dep / 2 ) ]: H# K% D G8 {6 G& o5 r
set d int (c / 5) * 53 ^ }0 P! `8 o
setxy ( xcor-of turtle d + x )
1 c, |2 n) Z1 O3 h' V5 l' p (ycor-of turtle d + y ) ; X, G$ J% M% Z) J. C
4 M8 W. `/ L/ S) @! i6 Z
6 t+ j5 c* G ?if (remainder who 5 = 3) [set k who% f# \6 K# a6 T2 Y
set x( Wid / 2)
4 M7 o( E, E. Z* q: d* j set y (0 - Dep / 2 ) ]
; c/ w4 Q& [ @$ H: z, b* s set f int (k / 5) * 5
9 T) k! |0 C1 h- a. h+ Z; h, u& v setxy ( xcor-of turtle f + x ); y* V, Y E O7 X' m2 s( f
(ycor-of turtle f + y ) # ^" Y( K- k% B6 ^& I
3 _3 O! R' M ?# H( q4 { J
! [& p! W4 V) m9 L
if (remainder who 5 = 4) [set g who+ b1 B( U4 Y: M! G
set x Wid / 2 ( [6 l0 a5 B4 |2 }. Y! S _' z
set y Dep / 2 ]
& L9 h6 s! k5 Z4 o5 Z) ? set h int (g / 5) * 5) I: [: ]) \+ H9 E+ n3 c" Y1 T% i
setxy ( xcor-of turtle h + x )6 n/ O/ T& s% P/ B8 [
(ycor-of turtle h + y )
6 E: a* i1 D% K! M4 i7 D9 }$ U , r! J, \; W. o! ~$ z
& p- @; d) z5 Z* K- E$ I ]8 u Z5 W8 U, G" E
end
% s. S% Y! n9 j% v- b. O3 A* k6 k- D! ?* y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|