|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; E. F$ p# }' w9 J* g. d3 Z, M @. p5 N
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ Y# R. A$ @7 V6 q; p( y/ k# Q8 C+ i8 q! \4 g. g
turtles-own [a b c d k f g h
$ ~& _: w; r: _" E% x x y ;; these are the leaf-turtle's offsets relative to center-turtle / A5 e" T+ y+ Z/ ?
]
9 }+ W* |" r: T4 w" i% z; a0 {& Eto new
, E& F0 s9 f8 Q! r( u$ K ca5 @ w7 a4 g) U: O
crt 5 * num_of_building
* g* [; L8 e3 f; a% }& W) b ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]7 C! ?5 V4 g" ]) p, j, K
scatter ;;keep center-turtle random positions
4 V. m/ _4 ]& D `) o6 r unit_plan ;;make up the building plan
: x! z3 O; b' z1 x+ d {end* Y0 @( @! J! M% R+ Y. a7 m* x8 b4 K
to scatter2 ^/ ~* F, i. ]/ s, p
ask turtles with [remainder who 5 = 0]
* F ~% ^/ i }9 h5 \% t; _* W[
/ n" V+ ]4 E+ S; Xset xcor xcor - 6 + random-float 15# l/ A3 S' A+ X* I" C0 L5 s
set ycor ycor - 6 + random-float 15
. `% ?% ^1 g h3 w2 M( J]
6 w9 C! e# [7 \* vend7 D4 L \: {* F" x- N+ N
to unit_plan
, ~6 }8 g& p+ t5 F* M: uask turtles [/ q# p' f6 Q3 h+ d! p
if (remainder who 5 = 1) [set a who
2 @; c+ k0 j. [/ ~ set x ( 0 - Wid / 2 )
6 f8 W9 d Q2 y; ~5 U* d% V set y Dep / 2 ]5 @5 n, @( H5 k2 ^0 P/ n7 g+ n
set b int (a / 5) * 56 [( p& X$ h5 T; U, u0 g
setxy ( xcor-of turtle b + x )$ w! U, e5 I. L
( ycor-of turtle b + y )
2 @' w% t& j+ Y- Bif (remainder who 5 = 2) [set c who- h4 `3 i/ e8 T9 j! p
set x ( 0 - Wid / 2 ) 4 B1 ^2 i! M3 c/ ^8 P3 t
set y (0 - Dep / 2 ) ]% }( o% w% C2 z: w; p# p
set d int (c / 5) * 5
$ F. B8 p. r( y: ~8 C8 y" b setxy ( xcor-of turtle d + x ): ]' h1 n* h$ t" Y$ H$ n% e
(ycor-of turtle d + y ) & T0 B% n4 l1 P
1 a1 l K) t8 l/ z
; I# A7 q" C6 \! f/ G0 mif (remainder who 5 = 3) [set k who
( A2 l7 l0 Q" y. Y6 ^ set x( Wid / 2) 8 e; |9 M, n; g+ U
set y (0 - Dep / 2 ) ]4 C9 J F9 G% C- u3 e6 |
set f int (k / 5) * 5$ o0 \' J$ v9 y: p6 u% T
setxy ( xcor-of turtle f + x )
6 ?# J' u" U) q% P (ycor-of turtle f + y )
3 J) V) O% }- N" Z8 g $ @1 Z) c' A$ s& V/ J+ l
3 g, `) b9 r5 A" i( t
if (remainder who 5 = 4) [set g who
) U# A7 F) H5 a( N' U set x Wid / 2
: x5 I( ]5 {0 H8 s2 W( h set y Dep / 2 ]
* h+ e+ ?( i# g/ s4 z6 w8 ], } set h int (g / 5) * 5
1 p5 x0 I% ?- M2 }2 b, H; E9 ~3 u7 P setxy ( xcor-of turtle h + x )6 m- U6 C0 w0 r, l, ?# D, t, E1 e
(ycor-of turtle h + y )
( H) s3 b: `" B5 u8 O 6 D: t1 N4 T( @" ^& O' O$ C
8 t% d! S. B3 s ], h4 [; V& [$ n5 W* t7 t) q
end% W9 H/ K/ M# v
! b* } K; ~1 D8 a" |/ b/ p[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|