|
|
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' E0 n- f0 P% S E! V" I
/ v; u; {1 G p/ r, }/ H
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 F, R! v* U# _/ j0 E0 R
( z6 j. x* i ^; F
turtles-own [a b c d k f g h
6 }" o B$ h1 |& ^5 t( D% ]0 K5 I! h* {9 } x y ;; these are the leaf-turtle's offsets relative to center-turtle
+ `# x- v2 Y: K d( k]
: m& F5 F. b5 k: j8 Kto new) d6 h* S4 A; C, H. {
ca5 Z% q- D' L) P5 j
crt 5 * num_of_building6 Y v& N- V/ g1 @8 ]
ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) k3 R( J( a3 V) w2 v: ^' S$ K& s scatter ;;keep center-turtle random positions * ?0 C" w) K! N" Z; y8 h
unit_plan ;;make up the building plan( |; @5 v% u3 C6 }$ u
end
& u# O! m9 t f+ e' a3 m& Q+ fto scatter9 W* a+ T: y2 B' V2 k9 o, D! K, ]
ask turtles with [remainder who 5 = 0]
* O# k0 e6 b1 B7 ^2 x& d[
; I* v; Z4 h& ^2 e8 X$ gset xcor xcor - 6 + random-float 15
+ ^9 q3 [+ Y/ a) b/ H/ l' G# ^set ycor ycor - 6 + random-float 15 Q, \) P- P% e2 y3 n1 B: h
]$ X. M' t6 Y3 R3 U2 t
end+ W% h/ h: u0 n
to unit_plan
3 J1 W/ a/ D0 ^: A6 j$ @" @ask turtles [
x5 z1 @7 P; m3 l- hif (remainder who 5 = 1) [set a who " h/ a Q3 i) w3 R: d3 U
set x ( 0 - Wid / 2 )
4 ? ?0 s& K0 W* ^! U- x9 m set y Dep / 2 ]3 M7 |- S" c- e' b% q/ t" D, M
set b int (a / 5) * 5
0 |2 [* `7 H& B+ S _& V# a7 b setxy ( xcor-of turtle b + x )) b0 ^2 a; F) O- q( E6 \" ~* G
( ycor-of turtle b + y )9 Z' H. v& V: Q8 V
if (remainder who 5 = 2) [set c who+ u* d3 k) P3 ?9 E* D
set x ( 0 - Wid / 2 )
4 k: k) J) Z9 X- l7 C5 P y set y (0 - Dep / 2 ) ]
- d; H9 A3 H9 b* r8 ^ set d int (c / 5) * 5
8 [6 R% x( g( q setxy ( xcor-of turtle d + x )
' R% g8 h; h' G2 k v (ycor-of turtle d + y )
3 D4 V& S- z9 I" {4 V
; M9 a5 S5 [/ U& W) i
7 U4 D3 G' R0 aif (remainder who 5 = 3) [set k who* W& F7 f, l. `- ~- p7 o% a
set x( Wid / 2) - D) a, E- s8 b' x t/ S
set y (0 - Dep / 2 ) ]
" r5 R" u1 q, {" W. M; Z* e( S& i set f int (k / 5) * 5: n8 A. P; \6 W/ F
setxy ( xcor-of turtle f + x )
" V8 w( k3 V4 r6 ^ (ycor-of turtle f + y ) $ ~. x( s2 G/ T, U1 x
" T9 @: e* D: E" q1 h
1 \9 l. _' Z, c5 D' z( ^
if (remainder who 5 = 4) [set g who
( _9 ?& D& c: E& ? set x Wid / 2
& M/ o0 T4 i' _6 Z set y Dep / 2 ]( |: H x1 j1 @' k3 b- S: U
set h int (g / 5) * 5( r7 ]* q0 \( ], s. o6 r
setxy ( xcor-of turtle h + x ). g' G. u# ]# ~ X, G% G/ @
(ycor-of turtle h + y ) q) ~: j3 h" ^
?) N$ w. F' h* ?" p3 v. ?( A
. O2 T: W7 j" f- q) K7 R( P5 e6 [ ]+ F- ?1 p6 c/ g8 B4 u+ D" X
end
; p% r+ k4 X8 T
/ e- `+ x `8 L v) ^" C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ] |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|