|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# w0 Y2 j/ \* n0 h2 D/ F9 m$ m) M/ F. V2 Q, j B9 q- d( T2 v. _
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ K+ V& M) e; y& T5 F$ [) {- u& h* v( U( f% I4 J' R
turtles-own [a b c d k f g h
; N. ~: v; t6 I3 M& Y. B x y ;; these are the leaf-turtle's offsets relative to center-turtle 6 L: E& p+ b0 z6 h
] r$ [" e* B; c6 ~0 w& \
to new
/ l' [) t. z' x! _4 G ca5 r/ Z0 A) a/ l" ?2 z* u# e
crt 5 * num_of_building9 C* @) l& \/ r
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 j/ O& {# f7 j% i+ a
scatter ;;keep center-turtle random positions
7 A4 k* [2 O- K2 P unit_plan ;;make up the building plan2 @/ b* u7 r+ _) k/ {7 K7 v0 N& b
end R! E8 r0 M# J, h9 B2 Z0 O
to scatter( w: [( D5 c6 H7 P
ask turtles with [remainder who 5 = 0]) |+ W( t& V8 s+ ~, n
[" T" l, V" G' i) L. u
set xcor xcor - 6 + random-float 15* i' `2 `4 T3 Z& Z* D
set ycor ycor - 6 + random-float 15
, _+ O8 B- I! N2 p# j0 Y: R0 ]7 `+ N]" c- {* q4 m$ ?% z; S: _# L
end+ ~4 C$ J( z' O, X
to unit_plan 5 b. s: X! g V$ k9 E
ask turtles [0 q9 F2 k. n' i4 F
if (remainder who 5 = 1) [set a who
p: a! z# u; u2 C2 u5 ~ set x ( 0 - Wid / 2 )
- \5 ^* R6 a2 f2 ~ set y Dep / 2 ]
. j6 ?" x. h" n; Z" Y0 K set b int (a / 5) * 5' \1 `: I6 Y* g: [% V: Y. o6 N' K& t
setxy ( xcor-of turtle b + x ). J- m4 H; X- K" O
( ycor-of turtle b + y )5 r7 b$ v8 X% D6 F
if (remainder who 5 = 2) [set c who1 l% A( ~7 w! @6 i9 G% w3 [
set x ( 0 - Wid / 2 )
+ p, U7 g5 j; v( a: m9 p+ R set y (0 - Dep / 2 ) ]4 A3 X: I V2 X& P
set d int (c / 5) * 5
% I g$ `' ?! v: u# G! [+ d! f7 K setxy ( xcor-of turtle d + x )
' z e- W9 r$ G) M (ycor-of turtle d + y ) 4 I5 I& V: Q+ I; w
% J9 v6 O# }1 H1 h) D `
8 g8 F$ L5 H' | P+ M% o5 ]if (remainder who 5 = 3) [set k who
" @7 N1 b9 F0 \5 `% p- w set x( Wid / 2) : o6 J K( _& v$ X
set y (0 - Dep / 2 ) ]
$ v6 S* h1 M( O7 e* f& D set f int (k / 5) * 5
1 f/ {! @ l3 c* D5 m5 z8 F5 | setxy ( xcor-of turtle f + x )
) k( ^9 c5 N5 D8 J( c1 [. u (ycor-of turtle f + y )
, B, t; H2 \4 P9 _
8 z N8 O) u: b v1 P 4 L$ e8 L3 }% y, K- B
if (remainder who 5 = 4) [set g who
) D* }: [" a! C# D, l1 M; l: n set x Wid / 2 $ \6 P! d, A, o% U( e; f$ {% t7 i
set y Dep / 2 ]
* q% w g: T3 _) A- I% ^ set h int (g / 5) * 5* T) |! i% Z+ X0 f2 \* s
setxy ( xcor-of turtle h + x )1 n- O9 O- q* O* R% q" p( q) s
(ycor-of turtle h + y ) O% P, q H8 N; W/ N; _
2 @ o" H5 u+ G' f. j# t7 e- t4 U
! t" Y4 p% U* N' u) k! ? ]
9 s: _% v- D( p' V( Q& Jend |3 a! b3 G+ l# N. G7 R
$ y5 f# v3 L% B# X6 G7 v
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|