|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# k2 R% C( Q4 G R
V, x6 K) Z) s2 \7 I" S* i# w4 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! L$ r3 z5 A5 ~, L2 c, |5 F
: [. P O) O, f. \- b8 v
turtles-own [a b c d k f g h! U7 g5 A9 z! y/ Y* R. _
x y ;; these are the leaf-turtle's offsets relative to center-turtle ( j2 c9 ^+ ]2 C* T: ~
]+ _1 o# x) [; \# o: X" ^
to new
\3 r' X4 ~8 k5 a$ M ca+ [, L0 ?7 U: j$ V# y
crt 5 * num_of_building: F, Z" i) N5 K) O
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% K9 Y" G6 Q* {- B9 T t( \
scatter ;;keep center-turtle random positions ' d/ l% E8 V0 _. h" t. v; b: Z
unit_plan ;;make up the building plan
( r# L; Y6 }9 H) Dend
- c. d! A4 n% j4 v8 y1 _: V1 Sto scatter
v4 z6 m6 U' |4 x" I5 b' s$ sask turtles with [remainder who 5 = 0]6 q1 o: n0 ]8 r* y" [( c
[' |3 K/ w# `0 p/ j
set xcor xcor - 6 + random-float 15
8 n0 ]( \+ G9 b% ]set ycor ycor - 6 + random-float 15
4 E/ G) {4 s+ b3 E/ R5 X]
% M y, h! [9 Y3 r% L* w' x+ _6 [end: X; e) ~5 n0 }& U% o& s5 d
to unit_plan . U* `# O$ e, t( B, M" t
ask turtles [
, p2 U9 _0 t, T7 k6 T- d) D6 z9 E% xif (remainder who 5 = 1) [set a who
; }6 t) _3 s; u: \+ x1 T# @! }1 N9 Z set x ( 0 - Wid / 2 ) L. y/ p! U+ ?, _9 C$ F
set y Dep / 2 ]
7 Y' }, `; m4 }2 W" Y% h set b int (a / 5) * 5
# [2 q8 F% m* y* Z setxy ( xcor-of turtle b + x )! j0 a- ], M! l4 a+ c/ t
( ycor-of turtle b + y )( ]. m* a+ g* Q* O0 i
if (remainder who 5 = 2) [set c who9 T C& w9 s3 G+ j6 Y
set x ( 0 - Wid / 2 ) 4 K- t; _3 ^- `# V) i# d6 i9 f
set y (0 - Dep / 2 ) ]# O& f4 X# m# [6 _) l2 Y% ?
set d int (c / 5) * 5/ d8 g& d+ {* u: m5 L
setxy ( xcor-of turtle d + x )
% O4 D& T" S h l. d- e (ycor-of turtle d + y )
( Q, P3 _; k R # v/ Z0 s* b n- ?$ c
& h+ H3 b% u* Z0 M" mif (remainder who 5 = 3) [set k who- X2 k v0 z. H W( s6 |- `8 P+ L
set x( Wid / 2)
6 S5 G* K) K9 \/ Q set y (0 - Dep / 2 ) ]; `: M* L& n4 T" g, k8 F/ I, ~5 e
set f int (k / 5) * 5
( b V; P* d! X7 S setxy ( xcor-of turtle f + x )
) h0 p, t% y, V0 n2 j (ycor-of turtle f + y ) 5 w: n& c! l1 K/ M& |4 ?' L/ J
; @( k4 j- L- q# R/ R" Y % y* |8 O3 P9 z9 d
if (remainder who 5 = 4) [set g who% B8 U/ G: V. Y* a1 D
set x Wid / 2 8 t7 U: F* C+ }* b& \
set y Dep / 2 ]0 W: f6 N4 ~0 j& E3 u$ l8 J
set h int (g / 5) * 5- w2 i$ i% f& h( _* V
setxy ( xcor-of turtle h + x )# r2 i: A C7 L4 M
(ycor-of turtle h + y ) $ O, s3 e, ~+ K S7 D* A
; y' x5 f4 E( ]9 }$ E3 g1 n' h
5 j/ a) J$ }: q" }! @9 ?4 j
]
7 b- R3 O+ K1 d) n: l) I. Mend
& t: g$ i" ]- f% U8 t! r, U; ^- F; ^2 W. y, f U
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|